/**
 * 核心服务接口sdk（golang版）
 *
 * @desc 啪啪运动 核心服务接口sdk
 * ---------------------------------------------------------------------
 * @author		tang <unphp@qq.com>
 * @date		2021-06-02
 * @copyright	core-utils
 * ---------------------------------------------------------------------
 */
package cooper

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

//NewPayCfgPayGetRequest ...账户管理 - 支付账户 - 详情
func (that *CooperClient) NewPayCfgPayGetRequest() *PayCfgPayGetRequest {
	return &PayCfgPayGetRequest{
		Request: Request{
			Client:            that,
			publicParamsSlice: []string{
				//...
			},
			apiAddress: "/pay/cfgPayGet",
		},
	}
}

//PayCfgPayGetRequest
type PayCfgPayGetRequest struct {
	Request
}

func (that *PayCfgPayGetRequest) SetTConfigId(value int64) *PayCfgPayGetRequest {
	that.initParams()
	that.params.Set("t_config_id", utils.ToString(value)) //账户id
	return that
}

//Params ...
func (that *PayCfgPayGetRequest) 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
}

type PayCfgPayGetResponse struct {
	TConfigId   int64  `json:"t_config_id"`
	AccountName string `json:"account_name"`
	TAppId      string `json:"t_app_id"`
	TMchId      string `json:"t_mch_id"`
	TSubMchId   string `json:"t_sub_mch_id"`
	TMchCertificateSerialNumber string `json:"t_mch_certificate_serial_number"`  //商户证书序列号
	TMchKey string `json:"t_mch_key"`  //商户APIv3密钥
	TWxpayKey string `json:"t_wxpay_key"`  //商户私钥
	TCateId int64 `json:"t_cate_id"`  //服务分类：11微信支付、21支付宝、31银联支付、41银联商务
	TTypeId int64 `json:"t_type_id"`  //服务性质：服务商、子商户、独立账户
	OrganizationId string `json:"organization_id"`  //刷掌机构ID
}

//Do ...
func (that *PayCfgPayGetRequest) Do() (*PayCfgPayGetResponse, error) {
	//返回data
	_data, _err := that.Client.Post(that.apiAddress, that)
	if _err != nil {
		return nil, _err
	}
	//
	_str, _err := json.Marshal(_data)
	if _err != nil {
		return nil, errors.New(that.apiAddress + _err.Error())
	}
	//返回结果
	_rs := new(PayCfgPayGetResponse)
	_err = json.Unmarshal(_str, &_rs)
	if _err != nil {
		return nil, errors.New(that.apiAddress + _err.Error())
	}
	return _rs, nil
}
