/**
 * 核心服务接口sdk（golang版）
 *
 * @desc 啪啪运动 核心服务接口sdk
 * ---------------------------------------------------------------------
 * @author		tang <tzf2273465837@126.com>
 * @date		2021-05-14
 * @copyright	core-utils
 * ---------------------------------------------------------------------
 */

package pposRequest

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

//NewCfgCloudPayGet 获取配置
func (that *PPOSClient) NewCfgCloudPayGet() *CfgCloudPayGetRequest {
	return &CfgCloudPayGetRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/cfg/cloudPay/getCfg",
		},
	}
}

type CfgCloudPayGetResponse struct {
	Config        GdConfig        `json:"config"`
	PayCodeConfig GdPayCodeConfig `json:"pay_code_config"`
}

type GdConfig struct {
	SiteCode   string `json:"site_code"`   //
	ItemCode   string `json:"item_code"`   //
	AddCode    string `json:"add_code"`    //
	PublicKey  string `json:"public_key"`  //
	PrivateKey string `json:"private_key"` //
}
type GdPayCodeConfig struct {
	PayType   string `json:"pay_type"`
	PayacctNo string `json:"payacct_no"`
	UnitCode  string `json:"unit_code"`
	UnitType  string `json:"unit_type"`
	UnitName  string `json:"unit_name"`
	Xzqh      string `json:"xzqh"`
	Zsbm      string `json:"zsbm"`
}

//CfgCloudPayGetRequest
type CfgCloudPayGetRequest struct {
	Request
}

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

//Do ...
func (that *CfgCloudPayGetRequest) Do() (*CfgCloudPayGetResponse, 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 + "请求响应格式不正确")
	}
	_str, _err := json.Marshal(_sliceData)
	if _err != nil {
		return nil, errors.New(that.apiAddress + _err.Error())
	}
	//返回结果
	_rs := new(CfgCloudPayGetResponse)
	_err = json.Unmarshal(_str, &_rs)
	if _err != nil {
		return _rs, errors.New(that.apiAddress + _err.Error())
	}
	//
	return _rs, nil
}
