/**
 * 核心服务接口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) NewUidUnLock() *UidUnLockRequest {
	return &UidUnLockRequest{
		Client:     that,
		apiAddress: "/mix/unLock",
	}
}

type UidUnLockReturn struct {
	SessionID string
}

//UidLockRequest 唯一id生成器
type UidUnLockRequest struct {
	Client     *CooperClient
	Domain     string `json:"domain"`     //名称
	SessionID  string `json:"session_id"` //初始化开始值
	apiAddress string
}

func (that *UidUnLockRequest) SetSession(domain, sessionID string) *UidUnLockRequest {
	that.Domain = domain
	that.SessionID = sessionID
	return that
}

//Params ...
func (that *UidUnLockRequest) Params() (url.Values, error) {
	var m = make(url.Values)
	m.Set("domain", utils.ToString(that.Domain))
	m.Set("session_id", utils.ToString(that.SessionID))
	return m, nil
}

//Do ...
func (that *UidUnLockRequest) Do() (*UidUnLockReturn, error) {
	//
	_data, _err := that.Client.Post(that.apiAddress, that)
	if _err != nil {
		return nil, _err
	}
	_sessionID := ""
	switch _v := _data.(type) {
	case string:
		_sessionID = _v
	case int64:
		_sessionID = utils.ToString(_v, true)
	case int:
		_sessionID = utils.ToString(_v, true)
	}
	return &UidUnLockReturn{_sessionID}, nil
}
