/**
 * 核心服务接口sdk（golang版）
 *
 * @desc 啪啪运动 核心服务接口sdk
 * ---------------------------------------------------------------------
 * @author		unphp <unphp@qq.com>
 * @date		2018-12-18
 * @copyright	core-utils
 * ---------------------------------------------------------------------
 */

package cooper

import (
	"net/url"
)

//NewGateAp ...
func (that *CooperClient) NewGateApKeep() *GateApKeepRequest {
	return &GateApKeepRequest{
		Client:     that,
		apiAddress: "/gateAp/keep",
	}
}

//GateApRequest 唯一id生成器
type GateApKeepRequest struct {
	Client     *CooperClient
	DeviceId   string `json:"device_id"` //设备ID
	AcsRes     string `json:"acs_res"`   //继电器 0:进门，1：出门，2：警报（火警）
	Status     string `json:"status"`    //开门保持时间(非必填，默认5秒)
	apiAddress string
}

func (that *GateApKeepRequest) SetApiAddress(apiAddress string) *GateApKeepRequest {
	that.apiAddress = apiAddress
	return that
}

func (that *GateApKeepRequest) SetDeviceId(deviceId string) *GateApKeepRequest {
	that.DeviceId = deviceId
	return that
}

func (that *GateApKeepRequest) SetAcsRes(acsRes string) *GateApKeepRequest {
	that.AcsRes = acsRes
	return that
}

func (that *GateApKeepRequest) SetKeepStatus(keepStatus string) *GateApKeepRequest {
	that.Status = keepStatus
	return that
}

//Params ...
func (that *GateApKeepRequest) Params() (url.Values, error) {
	var m = make(url.Values)
	m.Set("device_id", ToString(that.DeviceId))
	m.Set("acs_res", ToString(that.AcsRes))
	m.Set("status", ToString(that.Status))
	return m, nil
}

//Do ...
func (that *GateApKeepRequest) Do() (bool, error) {
	_, _err := that.Client.Post(that.apiAddress, that)
	if _err != nil {
		return false, _err
	}
	return true, nil
}
