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

package cooper

import (
	"PPOSUtils/utils"
	"net/url"
)

//NewUidGet ...
func (that *CooperClient) NewUsrK3Query() *Usrk3QueryRequest {
	return &Usrk3QueryRequest{
		Client:     that,
		apiAddress: "/usrK3/query",
	}
}

type Usrk3QueryReturn struct {
	Uid []int64
}

//UidRequest 唯一id生成器
type Usrk3QueryRequest struct {
	Client     *CooperClient
	DeviceId   string `json:"device_id"`  //设备ID
	DeviceCmd  string `json:"device_cmd"` //指令
	apiAddress string
}

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

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

func (that *Usrk3QueryRequest) SetDeviceCmd(deviceCmd string) *Usrk3QueryRequest {
	that.DeviceCmd = deviceCmd
	return that
}

//Params ...
func (that *Usrk3QueryRequest) Params() (url.Values, error) {
	var m = make(url.Values)
	m.Set("device_id", ToString(that.DeviceId))
	m.Set("device_cmd", ToString(that.DeviceCmd))
	return m, nil
}

//Do ...
func (that *Usrk3QueryRequest) Do() (string, error) {
	//
	_data, _err := that.Client.Post(that.apiAddress, that)
	if _err != nil {
		return "", _err
	}
	_res, _ok := _data.(map[string]interface{})
	if !_ok {
		return "", _err

	}
	return utils.ToString(_res["result"]), nil

}

