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

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

//NewPayCfgNameListRequest ...账户管理 - 支付账户 - 名称列表
func (that *CooperClient) NewPayCfgNameListRequest() *PayCfgNameListRequest {
	return &PayCfgNameListRequest{
		Request: Request{
			Client:            that,
			publicParamsSlice: []string{
				//...
			},
			apiAddress: "/pay/cfgNameList",
		},
	}
}

//PayCfgNameList
type PayCfgNameListRequest struct {
	Request
}


//Params ...
func (that *PayCfgNameListRequest) 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 CfgNameListResponse struct {
	TConfigId int64 `json:"t_config_id"`
	AccountName string `json:"account_name"`
}

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