package cooper

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

//灯控开关模组列表状态
func (that *CooperClient) NewUsrK3LightModListStateRequest() *UsrK3LightModListStateRequest {
	return &UsrK3LightModListStateRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/usrK3/lightModListState",
		},
	}
}

//UsrK3LightModListStateRequest ...
type UsrK3LightModListStateRequest struct {
	Request
}

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

//条数
func (that *UsrK3LightModListStateRequest) SetSize(value int64) *UsrK3LightModListStateRequest {
	that.initParams()
	that.params.Set("size", ToString(value))
	return that
}

//线路id
func (that *UsrK3LightModListStateRequest) SetDevIds(value string) *UsrK3LightModListStateRequest {
	that.initParams()
	that.params.Set("dev_ids", value)
	return that
}

//Params ...
func (that *UsrK3LightModListStateRequest) 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 UsrK3LightModListStateResponse struct {
    Page       int64  `json:"page"`
	Size       int64  `json:"size"`
	Count      int64  `json:"count"`
	List       []*UsrK3LightModListStateTemp  `json:"list"`
}

type UsrK3LightModListStateTemp struct {
	UsrK3LightModGetResponse
	IdStr int64  `json:"id_str"`
	LineState  []int64 `json:"line_state"`
}

//Do ...
func (that *UsrK3LightModListStateRequest) Do() (*UsrK3LightModListStateResponse, 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(UsrK3LightModListStateResponse)
	_err = json.Unmarshal(_str, &_rs)
	if _err != nil {
		return _rs, errors.New(that.apiAddress + "Unmarshal failed!" + _err.Error())
	}
	return _rs, nil
}
