package pass

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

//NewUidGetShortUrl ...
func (that *PassClient) NewUidGetShortUrl() *UidGetShortUrlRequest {
	return &UidGetShortUrlRequest{
		Request: Request{
			Client:            that,
			publicParamsSlice: []string{
				//...
			},
			apiAddress: "uid/shortUrl/get",
		},
	}
}

//UidGetShortUrlRequest 获取原链接
type UidGetShortUrlRequest struct {
	Request
}

func (that *UidGetShortUrlRequest) SetShortCode(value string) *UidGetShortUrlRequest {
	that.initParams()
	that.params.Set("short_code", value)
	return that
}

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