package cooper

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

//灯控开关模组状态查询
func (that *CooperClient) NewUsrK3LightModQueryRequest() *UsrK3LightModQueryRequest {
	return &UsrK3LightModQueryRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/usrK3/lightModQuery",
		},
	}
}

//UsrK3LightModQueryRequest ...
type UsrK3LightModQueryRequest struct {
	Request
}

//设备ID
func (that *UsrK3LightModQueryRequest) SetModId(value int64) *UsrK3LightModQueryRequest {
	that.initParams()
	that.params.Set("mod_id", ToString(value))
	return that
}

//Params ...
func (that *UsrK3LightModQueryRequest) 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 UsrK3LightModQueryResponse struct {
	UsrK3LightModGetResponse
	LineState  []int64 `json:"line_state"`
}

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