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

package cooper

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

//NewHandMachine ...
func (that *CooperClient) NewHandMachine() *HandMachineRequest {
	return &HandMachineRequest{
		Client:     that,
		apiAddress: "",
	}
}

//HandMachineRequest
type HandMachineRequest struct {
	Client     *CooperClient
	postData   string
	apiAddress string
	imageUrl   string
	errorCode  string
}

//确认用户是否可以获取手环
func (that *HandMachineRequest) GetBraceletCheck(postData string) *HandMachineRequest {
	that.postData = postData
	that.apiAddress = "/hand/checkUser"
	return that
}

//发放手环接口
func (that *HandMachineRequest) CheckBackBracelet(postData string) *HandMachineRequest {
	that.postData = postData
	that.apiAddress = "/hand/sendRing"
	return that
}

//归还手环核验
func (that *HandMachineRequest) BackMemberBracelet(postData string) *HandMachineRequest {
	that.postData = postData
	that.apiAddress = "/hand/checkBackRing"
	return that
}

//归还手环
func (that *HandMachineRequest) DoMemberBracelet(postData string) *HandMachineRequest {
	that.postData = postData
	that.apiAddress = "/hand/returnRing"
	return that
}

//Params ...
func (that *HandMachineRequest) Params() (url.Values, error) {
	var m = make(url.Values)
	m.Set("data", that.postData)
	return m, nil
}

//Do ...
func (that *HandMachineRequest) Do() (utils.Mp, error) {
	//
	_data, _err := that.Client.Post(that.apiAddress, that)
	if _err != nil {
		return nil, _err
	}
	fmt.Println("=====000099999====", _data)
	_type, _ok := _data.(map[string]interface{})
	if !_ok {
		return nil, errors.New("响应错误,请检查open调用的cooper的sdk")
	}
	return _type, nil
}
