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

package pposRequest

import (
	"errors"
	"net/url"
)

//NewCfgTradeGetByIDs 获取配置
func (that *PPOSClient) NewCfgAliPayGetByCp() *CfgAliPayGetByCpRequest {
	return &CfgAliPayGetByCpRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/cfg/aliPay/get",
		},
	}
}

type CfgAliPayGetByCpResponse struct {
	CompanyId  int64  `json:"company_id"`  //公司ID
	AliAppId   string `json:"ali_app_id"`  //开发者ID（appID）
	MchId      string `json:"mch_id"`      //mchID
	PrivateKey string `json:"private_key"` //私钥
	PublicKey  string `json:"public_key"`  //公钥
	Status     int64  `json:"status"`      //授权状态
	Account    string `json:"account"`     //登录账号
	AuthToken  string `json:"auth_token"`  //子商户ID
}

//CfgWxPublicGetByCpRequest 业务类别
type CfgAliPayGetByCpRequest struct {
	Request
	CompanyId  int64 `json:"company_id"`  //公司ID
	BusinessId int64 `json:"business_id"` //商户ID
}

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

//Do ...
func (that *CfgAliPayGetByCpRequest) Do() (*CfgAliPayGetByCpResponse, 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(CfgAliPayGetByCpResponse)
	if _err := that.ParseResponeMp(_rs, _sliceData); _err != nil {
		return nil, errors.New(that.apiAddress + "请求响应格式化异常:" + _err.Error())
	}
	//
	return _rs, nil
}
