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

package pposRequest

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

//NewCfgRzPayGet 获取配置
func (that *PPOSClient) NewCfgRzPayGet() *CfgRzPayGetRequest {
	return &CfgRzPayGetRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/cfg/rzPay/getCfg",
		},
	}
}

type CfgRzPayGetResponse struct {
	AppId   string `json:"app_id"`   //
	MchId   string `json:"mch_id"`   //
	SceneId string `json:"scene_id"` //
	ApiKey  string `json:"api_key"`  //
}

//CfgRzPayGetRequest
type CfgRzPayGetRequest struct {
	Request
}

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

//Do ...
func (that *CfgRzPayGetRequest) Do() (*CfgRzPayGetResponse, 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(CfgRzPayGetResponse)
	_err = json.Unmarshal(_str, &_rs)
	if _err != nil {
		return _rs, errors.New(that.apiAddress + _err.Error())
	}
	//
	return _rs, nil
}
