/**
 * 核心服务接口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) NewGateApCheck() *GateApCheckRequest {
	return &GateApCheckRequest{
		Client:     that,
		apiAddress: "/gateAp/check",
	}
}

//GateApCheckRequest
type GateApCheckRequest struct {
	Client     *CooperClient
	DeviceId   string `json:"device_id"`  //设备ID
	CheckType  string `json:"check_type"` //核验类型
	CheckData  string `json:"check_data"` //核验数据
	apiAddress string
}

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

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

func (that *GateApCheckRequest) SetCheckType(checkType string) *GateApCheckRequest {
	that.CheckType = checkType
	return that
}

func (that *GateApCheckRequest) SetCheckData(checkData string) *GateApCheckRequest {
	that.CheckData = checkData
	return that
}

//Params ...
func (that *GateApCheckRequest) Params() (url.Values, error) {
	var m = make(url.Values)
	m.Set("device_id", ToString(that.DeviceId))
	m.Set("check_type", ToString(that.CheckType))
	m.Set("check_data", ToString(that.CheckData))
	return m, nil
}

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