package cooper

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

//获取灯控设备状态
func (that *CooperClient) NewUsrK3GetByIdsRequest() *UsrK3GetByIdsRequest {
	return &UsrK3GetByIdsRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/usrK3/getByIds",
		},
	}
}

//UsrK3GetByIdsRequest ...
type UsrK3GetByIdsRequest struct {
	Request
}

//设备ID
func (that *UsrK3GetByIdsRequest) SetDevIds(value string) *UsrK3GetByIdsRequest {
	that.initParams()
	that.params.Set("dev_ids", value)
	return that
}

//Params ...
func (that *UsrK3GetByIdsRequest) 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 UsrK3ByIdsResponse struct {
	DeviceId string `json:"device_id"`
	DeviceName string `json:"device_name"`
	CmdType int64 `json:"cmd_type"`
	Online   int64  `json:"online"`
	CTime    string `json:"c_time"`
}

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