/**
 * 核心服务接口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) NewUsrk3() *Usrk3Request {
	return &Usrk3Request{
		Client:     that,
		apiAddress: "/usrK3/cmd",
	}
}

type Usrk3Return struct {
	Uid []int64
}

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

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

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

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

//Params ...
func (that *Usrk3Request) 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 *Usrk3Request) 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

}

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

	}
	return _res, nil

}
