package cooper

import (
	"errors"
	"net/url"
)

//修改灯路配置
func (that *CooperClient) NewUsrK3LightLineEditRequest() *UsrK3LightLineEditRequest {
	return &UsrK3LightLineEditRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/usrK3/lightLineEdit",
		},
	}
}

//UsrK3LightLineEditRequest ...
type UsrK3LightLineEditRequest struct {
	Request
}

//线路id
func (that *UsrK3LightLineEditRequest) SetLineId(value int64) *UsrK3LightLineEditRequest {
	that.initParams()
	that.params.Set("line_id", ToString(value))
	return that
}

//线路名称
func (that *UsrK3LightLineEditRequest) SetLineName(value string) *UsrK3LightLineEditRequest {
	that.initParams()
	that.params.Set("line_name", value)
	return that
}

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

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

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

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

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

//开启状态
func (that *UsrK3LightLineEditRequest) SetIsEnable(value int64) *UsrK3LightLineEditRequest {
	that.initParams()
	that.params.Set("is_enable", ToString(value))
	return that
}

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