package cooper

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

//灯路配置查询
func (that *CooperClient) NewUsrK3LightModGetRequest() *UsrK3LightModGetRequest {
	return &UsrK3LightModGetRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/usrK3/lightModGet",
		},
	}
}

//UsrK3LightModGetRequest ...
type UsrK3LightModGetRequest struct {
	Request
}

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

//Params ...
func (that *UsrK3LightModGetRequest) 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 UsrK3LightModGetResponse struct {
	DevId      string `json:"dev_id"`                                           //灯控设备id
	ModId      int64  `json:"mod_id"`                                         //开关模块id（灯路关联id）
	ModName    string `json:"mod_name"`                                      //开关模组名称（模组安装在场馆灯箱的位置）
	ModType    int64  `json:"mod_type"`                                             //开关模组类型（6路/8路/12路）
	ModSort    int64  `json:"mod_sort"`                                           //开关模组的拨片编号
	UTime      int64  `json:"u_time"`                        //
	CTime      int64  `json:"c_time"`                        //
	CTimeStr   string `json:"c_time_str"`                        //
	UTimeStr   string `json:"u_time_str"`                        //
}

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