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

package pposRequest

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

//NewCfgUmsPayGetFtpConfig 获取银联商户所有的ftp配置
func (that *PPOSClient) NewCfgUmsPayGetFtpConfig() *CfgUmsPayGetFtpConfig {
	return &CfgUmsPayGetFtpConfig{
		Request: Request{
			Client:     that,
			apiAddress: "/cfg/umsPay/getFtpConfig",
		},
	}
}

type CfgUmsPayGetFtpConfigResponse struct {
	CompanyId int64  `json:"company_id"`
	Name      string `json:"name"`
	Pass      string `json:"pass"`
}

//CfgUmsPayGetFtpConfig
type CfgUmsPayGetFtpConfig struct {
	Request
}

//Params ...
func (that *CfgUmsPayGetFtpConfig) 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 *CfgUmsPayGetFtpConfig) Do() ([]*CfgUmsPayGetFtpConfigResponse, error) {
	//
	_data, _err := that.Client.GetData(that.apiAddress, that)
	if _err != nil {
		return nil, _err
	}
	//返回结果
	_rs := []*CfgUmsPayGetFtpConfigResponse{}
	_byte, _err := json.Marshal(_data)
	if _err != nil {
		return nil, _err
	}
	_err = json.Unmarshal(_byte, &_rs)
	if _err != nil {
		return nil, errors.New(that.apiAddress + _err.Error())
	}
	//
	return _rs, nil
}
