package pass

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

//NewUidGet ...
func (that *PassClient) NewUidUnLock() *UidUnLockRequest {
	return &UidUnLockRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/mix/unLock",
		},
	}
}

type UidUnLockReturn struct {
	SessionID string
}

//UidLockRequest 唯一id生成器
type UidUnLockRequest struct {
	Request
}

func (that *UidUnLockRequest) SetSession(domain, sessionID string) *UidUnLockRequest {
	that.initParams()
	that.params.Set("domain", domain)        //名称
	that.params.Set("session_id", sessionID) //初始化开始值
	return that
}

//Params ...
func (that *UidUnLockRequest) 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 *UidUnLockRequest) Do() (*UidUnLockReturn, error) {
	_data, _err := that.Client.GetData(that.apiAddress, that)
	if _err != nil {
		return nil, _err
	}
	_sessionID := ""
	switch _v := _data.(type) {
	case map[string]interface{}:
		_sessionID = utils.ToString(_v["result"], true)
	case string:
		_sessionID = _v
	case int64:
		_sessionID = utils.ToString(_v, true)
	case int:
		_sessionID = utils.ToString(_v, true)
	}
	return &UidUnLockReturn{_sessionID}, nil
}
