package cooper

import (
	"errors"
	"net/url"
)

//添加灯路配置
func (that *CooperClient) NewUsrK3LightLineAddRequest() *UsrK3LightLineAddRequest {
	return &UsrK3LightLineAddRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/usrK3/lightLineAdd",
		},
	}
}

//UsrK3LightLineAddRequest ...
type UsrK3LightLineAddRequest struct {
	Request
}

//LineName
func (that *UsrK3LightLineAddRequest) SetLineName(value string) *UsrK3LightLineAddRequest {
	that.initParams()
	that.params.Set("line_name", value)
	return that
}

//串口设备id
func (that *UsrK3LightLineAddRequest) SetDeviceId(value int64) *UsrK3LightLineAddRequest {
	that.initParams()
	that.params.Set("device_id", ToString(value))
	return that
}

//串口设备类型
func (that *UsrK3LightLineAddRequest) SetDeviceType(value int64) *UsrK3LightLineAddRequest {
	that.initParams()
	that.params.Set("device_type", ToString(value))
	return that
}

//开灯指令(用户编辑的部分指令)
func (that *UsrK3LightLineAddRequest) SetTurnOnOrder(value string) *UsrK3LightLineAddRequest {
	that.initParams()
	that.params.Set("turn_on_order", value)
	return that
}

//关灯指令(用户编辑的部分指令)
func (that *UsrK3LightLineAddRequest) SetTurnOffOrder(value string) *UsrK3LightLineAddRequest {
	that.initParams()
	that.params.Set("turn_off_order", value)
	return that
}

//灯控设备ID
func (that *UsrK3LightLineAddRequest) SetIdentifier(value string) *UsrK3LightLineAddRequest {
	that.initParams()
	that.params.Set("identifier", value)
	return that
}

//Params ...
func (that *UsrK3LightLineAddRequest) 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 *UsrK3LightLineAddRequest) Do() (interface{}, error) {
	//返回data
	_data, _err := that.Client.Post(that.apiAddress, that)
	if _err != nil {
		return nil, _err
	}
	return _data, nil
}
