/**
 * 核心服务接口sdk（golang版）
 *
 * @desc 啪啪运动 核心服务接口sdk
 * ---------------------------------------------------------------------
 * @author		logan <lgq092@163.com>
 * @date		2020-01-06
 * @copyright	core-utils
 * ---------------------------------------------------------------------
 */

package pposRequest

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

//NewCfgAllPayGet 获取配置
func (that *PPOSClient) NewCfgAllPayGet() *CfgAllPayGetRequest {
	return &CfgAllPayGetRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/cfg/allPayStadium/getCfg",
		},
	}
}

type CfgAllPayGetResponse struct {
	AppId     string `json:"app_id"`     //appId
	CompanyId int64  `json:"company_id"` //公司ID
	Status    int64  `json:"status"`     //授权状态
	MchId     string `json:"mch_id"`     //MchId
	ApiKey    string `json:"api_key"`    //密钥
	SubAppId  string `json:"sub_app_id"` //公众号id
	Tid       string `json:"tid"`        //终端号

}

//CfgAllPayGetRequest 业务类别
type CfgAllPayGetRequest struct {
	Request
}

func (that *CfgAllPayGetRequest) SetOrderFrom(value int64) *CfgAllPayGetRequest {
	that.initParams()
	that.params.Set("order_from", utils.ToString(value))
	return that
}

//Params ...
func (that *CfgAllPayGetRequest) Params() (url.Values, error) {
	that.initParams()
	_params := that.params
	return _params, nil
}

//Do ...
func (that *CfgAllPayGetRequest) Do() (*CfgAllPayGetResponse, error) {
	//
	_data, _err := that.Client.GetData(that.apiAddress, that)
	if _err != nil {
		return nil, _err
	}
	//
	_sliceData, _ok := _data.(map[string]interface{})
	if !_ok {
		return nil, errors.New(that.apiAddress + "请求响应格式不正确")
	}
	_rs := new(CfgAllPayGetResponse)
	if _err := that.ParseResponeMp(_rs, _sliceData, false); _err != nil {
		return nil, errors.New(that.apiAddress + "请求响应格式化异常:" + _err.Error())
	}
	//
	return _rs, nil
}
