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

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

//NewUidGet ...
func (that *CooperClient) NewLockerGetRequest() *LockerGetRequest {
	return &LockerGetRequest{
		Request: Request{
			Client:     that,
			publicParamsSlice: []string{"mac"},
			apiAddress:"/locker/getByMac",
		},
	}
}

//LockerGetRequest
type LockerGetRequest struct {
	Request
	Mac string `json:"mac"`
}

func (that *LockerGetRequest) SetMac(mac string) *LockerGetRequest {
	that.initParams()
	that.params.Set("mac", utils.ToString(mac))
	return that
}

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

//Do ...
func (that *LockerGetRequest) Do() ([]*LockerGetResponse, error) {
	//返回data
	_data, _err := that.Client.Post(that.apiAddress,that)
	if _err != nil {
		return nil, _err
	}

	_rs := []*LockerGetResponse{}
	_sliceData, _ok := _data.([]interface{})
	if !_ok {
		return nil, errors.New(that.apiAddress + "请求响应格式不正确")
	}
	if len(_sliceData) < 1{
		return _rs,nil
	}
	for _, _v := range _sliceData {
		_vData, _ok := _v.(map[string]interface{})
		if !_ok {
			return nil, errors.New(that.apiAddress + "请求响应格式不正确2")
		}
		_tmp := new(LockerGetResponse)
		if _err := that.ParseResponeMp(_tmp, _vData); _err != nil {
			return nil, errors.New(that.apiAddress + "请求响应格式化异常:" + _err.Error())
		}
		_rs = append(_rs, _tmp)
	}


	//返回结果
	//_rs := []*LockerGetResponse{}
	//_sliceData, _ok := _data.([]interface{})
	//if !_ok {
	//	return nil, errors.New(that.apiAddress + "请求响应格式不正确")
	//}
	//for _, _v := range _sliceData {
	//	_vData, _ok := _v.(map[string]interface{})
	//	if !_ok {
	//		return nil, errors.New(that.apiAddress + "请求响应格式不正确2")
	//	}
	//	_tmp := new(LockerGetResponse)
	//	if _err := that.ParseResponeMp(_tmp, _vData); _err != nil {
	//		return nil, errors.New(that.apiAddress + "请求响应格式化异常:" + _err.Error())
	//	}
	//	_rs = append(_rs, _tmp)
	//}
	return _rs, nil
}