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

package pposRequest

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

//NewCfgCloudPayGetCodes 根据对账标识code获取配置
func (that *PPOSClient) NewCfgCloudPayGetCodes() *CfgCloudPayGetCodes {
	return &CfgCloudPayGetCodes{
		Request: Request{
			Client:     that,
			apiAddress: "/cfg/cloudPay/getCodes",
		},
	}
}

type CfgCloudPayGetCodesResponse struct {
	CompanyId  int64  `json:"company_id"`
	BusinessId int64  `json:"business_id"`
	MftCode    string `json:"mft_code"`
}

//CfgCloudPayGetCodes
type CfgCloudPayGetCodes struct {
	Request
}

func (that *CfgCloudPayGetCodes) SetMftCodes(value string) *CfgCloudPayGetCodes {
	that.initParams()
	that.params.Set("mft_codes", value) //对账标识(用于对账)
	return that
}

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

//Do ...
func (that *CfgCloudPayGetCodes) Do() ([]*CfgCloudPayGetCodesResponse, error) {
	//
	_data, _err := that.Client.GetData(that.apiAddress, that)
	if _err != nil {
		return nil, _err
	}
	//
	_sliceData, _ok := _data.([]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 := make([]*CfgCloudPayGetCodesResponse, 0)
	_err = json.Unmarshal(_str, &_rs)
	if _err != nil {
		return _rs, errors.New(that.apiAddress + _err.Error())
	}
	//
	return _rs, nil
}
