package cooper

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

//灯控开关模组查询
func (that *CooperClient) NewUsrK3LightModGetByModIdsRequest() *UsrK3LightModGetByModIdsRequest {
	return &UsrK3LightModGetByModIdsRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/usrK3/lightModGetByModIds",
		},
	}
}

//UsrK3LightModGetByModIdsRequest ...
type UsrK3LightModGetByModIdsRequest struct {
	Request
}

func (that *UsrK3LightModGetByModIdsRequest) SetModIds(value string) *UsrK3LightModGetByModIdsRequest {
	that.initParams()
	that.params.Set("mod_ids", value)
	return that
}

//Params ...
func (that *UsrK3LightModGetByModIdsRequest) 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
}

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