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

package cooper

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

//NewUidGet ...
func (that *CooperClient) NewAlfFace() *AlfFaceRequest {
	return &AlfFaceRequest{
		Client:     that,
		apiAddress: "/uid/get",
	}
}

//UidRequest 唯一id生成器
type AlfFaceRequest struct {
	Client     *CooperClient
	postData   string
	apiAddress string
	imageUrl   string
	errorCode  string
}

func (that *AlfFaceRequest) AlfLogin(postData string) *AlfFaceRequest {
	that.postData = postData
	that.apiAddress = "/alf/login"
	return that
}

func (that *AlfFaceRequest) AlfTime(postData string) *AlfFaceRequest {
	that.postData = postData
	that.apiAddress = "/alf/serverConfig/time"
	return that
}

func (that *AlfFaceRequest) AlfConfig(postData string) *AlfFaceRequest {
	that.postData = postData
	that.apiAddress = "/alf/config"
	return that
}

func (that *AlfFaceRequest) AlfCompanyConfig(postData string) *AlfFaceRequest {
	that.postData = postData
	that.apiAddress = "/alf/company/config"
	return that
}

func (that *AlfFaceRequest) AlfThislocality(postData, imageUrl string) *AlfFaceRequest {
	that.postData = postData
	that.imageUrl = imageUrl
	that.apiAddress = "/alf/thislocality"
	return that
}

func (that *AlfFaceRequest) AlfOther(postData string) *AlfFaceRequest {
	that.postData = postData
	that.apiAddress = "/alf/group"
	return that
}

//Params ...
func (that *AlfFaceRequest) Params() (url.Values, error) {
	var m = make(url.Values)
	m.Set("data", that.postData)
	if that.imageUrl != "" {
		m.Set("image_url", that.imageUrl)
	}
	return m, nil
}

//Do ...
func (that *AlfFaceRequest) Do() (utils.Mp, error) {
	//
	_data, _err := that.Client.Post(that.apiAddress, that)
	if _err != nil {
		that.errorCode = utils.ToString(_data)
		return nil, _err
	}
	fmt.Println("=====000099999====", _data)
	_type, _ok := _data.(map[string]interface{})
	if !_ok {
		return nil, errors.New("响应错误,请检查open调用的cooper的sdk")
	}
	return _type, nil
}
