package pposRequest

import (
	"errors"
	"net/url"
)

//NewHandGetBraceletCheckRequest 手环机业务接口 （用户领取手环核验）
func (that *PPOSClient) NewHandGetBraceletCheckRequest() *HandGetBraceletCheckRequest {
	return &HandGetBraceletCheckRequest{
		Request: Request{
			Client: that,
			publicParamsSlice: []string{
				"code",
				"device_id",
				"check_type",
			},
			apiAddress: "/enterAdmin/braceletYj/borrowBracelet",
		},
	}
}

//LockerGetCountRequest ...
type HandGetBraceletCheckRequest struct {
	Request
}

func (that *HandGetBraceletCheckRequest) SetCode(value string) *HandGetBraceletCheckRequest {
	that.initParams()
	that.params.Set("code", value) //手环标识码
	return that
}
func (that *HandGetBraceletCheckRequest) SetDeviceID(value string) *HandGetBraceletCheckRequest {
	that.initParams()
	that.params.Set("device_id", value) //设备编号(验证云提供)
	return that
}
func (that *HandGetBraceletCheckRequest) SetCheckType(value string) *HandGetBraceletCheckRequest {
	that.initParams()
	that.params.Set("check_type", value) //验证识别类型（1 二维码 2云验证id）
	return that
}

//Params ...
func (that *HandGetBraceletCheckRequest) Params() (url.Values, error) {
	that.initParams()
	_params := that.params
	if that.publicParamsSlice != nil {
		for _, _v := range that.publicParamsSlice {
			if _params.Get(_v) == "" {
				return nil, errors.New(that.apiAddress + "缺少参数:" + _v)
			}
		}
	}
	return _params, nil
}

type HandGetBraceletCheckResponse struct {
	UserId string `json:"user_id"` //用户ID
}

//Do ...
func (that *HandGetBraceletCheckRequest) Do() (*HandGetBraceletCheckResponse, error) {
	//返回data
	_data, _err := that.Client.GetData(that.apiAddress, that)
	if _err != nil {
		return nil, _err
	}
	_vData, _ok := _data.(map[string]interface{})
	if !_ok {
		return nil, errors.New(that.apiAddress + "请求响应格式不正确2")
	}
	//返回结果
	_rs := new(HandGetBraceletCheckResponse)
	if _err := that.ParseResponeMp(_rs, _vData, false); _err != nil {
		return nil, errors.New(that.apiAddress + "请求响应格式化异常:" + _err.Error())
	}
	return _rs, nil
}
