package cooper

import (
	"encoding/json"
	"errors"
	"net/url"
)

//灯路配置列表筛选
func (that *CooperClient) NewUsrK3LightModListRequest() *UsrK3LightModListRequest {
	return &UsrK3LightModListRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/usrK3/lightModList",
		},
	}
}

//UsrK3LightModListRequest ...
type UsrK3LightModListRequest struct {
	Request
}

//页码
func (that *UsrK3LightModListRequest) SetPage(value int64) *UsrK3LightModListRequest {
	that.initParams()
	that.params.Set("page", ToString(value))
	return that
}

//页码
func (that *UsrK3LightModListRequest) SetSize(value int64) *UsrK3LightModListRequest {
	that.initParams()
	that.params.Set("size", ToString(value))
	return that
}

//线路id
func (that *UsrK3LightModListRequest) SetModId(value int64) *UsrK3LightModListRequest {
	that.initParams()
	that.params.Set("mod_id", ToString(value))
	return that
}

//开关模块名称
func (that *UsrK3LightModListRequest) SetModName(value string) *UsrK3LightModListRequest {
	that.initParams()
	that.params.Set("mod_name", value)
	return that
}

//设备拨片编号
func (that *UsrK3LightModListRequest) SetModSort(value int64) *UsrK3LightModListRequest {
	that.initParams()
	that.params.Set("mod_sort", ToString(value))
	return that
}

//设备类型
func (that *UsrK3LightModListRequest) SetModType(value int64) *UsrK3LightModListRequest {
	that.initParams()
	that.params.Set("mod_type", ToString(value))
	return that
}

//设备类型
func (that *UsrK3LightModListRequest) SetDevId(value string) *UsrK3LightModListRequest {
	that.initParams()
	that.params.Set("dev_id", value)
	return that
}

//Params ...
func (that *UsrK3LightModListRequest) Params() (url.Values, error) {
	that.initParams()
	_params := that.params
	if that.publicParamsSlice != nil {
		for _, _v := range that.publicParamsSlice {
			if _params.Get(_v) == "" {
				return nil, errors.New(that.apiAddress + "缺少参数:" + _v)
			}
		}
	}
	return _params, nil
}

type UsrK3LightModListResponse struct {
    Page       int64  `json:"page"`
	Size       int64  `json:"size"`
	Count      int64  `json:"count"`
	List       []*UsrK3LightModListTemp  `json:"list"`
}

type UsrK3LightModListTemp struct {
	UsrK3LightModGetResponse
	IdStr int64  `json:"id_str"`
}

//Do ...
func (that *UsrK3LightModListRequest) Do() (*UsrK3LightModListResponse, error) {
	//返回data
	_data, _err := that.Client.Post(that.apiAddress, that)
	if _err != nil {
		return nil, _err
	}
	//
	_str, _err := json.Marshal(_data)
	if _err != nil {
		return nil, errors.New(that.apiAddress + "Marshal failed!" + _err.Error())
	}
	//返回结果
	_rs := new(UsrK3LightModListResponse)
	_err = json.Unmarshal(_str, &_rs)
	if _err != nil {
		return _rs, errors.New(that.apiAddress + "Unmarshal failed!" + _err.Error())
	}
	return _rs, nil
}
