package cooper

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

//单条查询灯路配置
func (that *CooperClient) NewUsrK3LightLineListRequest() *UsrK3LightLineListRequest {
	return &UsrK3LightLineListRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/usrK3/lightLineList",
		},
	}
}

//UsrK3LightLineListRequest ...
type UsrK3LightLineListRequest struct {
	Request
}

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

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

//识别符
func (that *UsrK3LightLineListRequest) SetIdentifier(value string) *UsrK3LightLineListRequest {
	that.initParams()
	that.params.Set("identifier", value)
	return that
}

//多个灯控ID
func (that *UsrK3LightLineListRequest) SetIdentifiers(value string) *UsrK3LightLineListRequest {
	that.initParams()
	that.params.Set("identifiers", value)
	return that
}

//多个线路ID
func (that *UsrK3LightLineListRequest) SetLineIds(value string) *UsrK3LightLineListRequest {
	that.initParams()
	that.params.Set("line_ids", value)
	return that
}

//多个线路ID
func (that *UsrK3LightLineListRequest) SetIsEnable(value int64) *UsrK3LightLineListRequest {
	that.initParams()
	that.params.Set("is_enable", ToString(value))
	return that
}

//Params ...
func (that *UsrK3LightLineListRequest) 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 UsrK3LightLineListResponse struct {
	Page int64 `json:"page"`
	Size int64 `json:"size"`
	Count int64 `json:"count"`
	List []*UsrK3LightLineListTemp `json:"list"`
	Identifier string `json:"identifier"`
}

type UsrK3LightLineListTemp struct {
	UsrK3LightLineGetResponse
	IdStr int64 `json:"id_str"`
}


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