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

package cooper

import (
	"errors"
	"net/url"
)

//NewUidSetShortUrl ...
func (that *CooperClient) NewUidSetShortUrl() *UidSetShortUrlRequest {
	return &UidSetShortUrlRequest{
		Request: Request{
			Client:            that,
			publicParamsSlice: []string{
				//...
			},
			apiAddress: "/mix/setShortUrl",
		},
	}
}

//UidSetShortUrlRequest 生成短链接
type UidSetShortUrlRequest struct {
	Request
}

func (that *UidSetShortUrlRequest) SetSrcUrl(value string) *UidSetShortUrlRequest {
	that.initParams()
	that.params.Set("src_url", value)
	return that
}

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