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

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

//NewPayCfgAccountRequest ... 支付账户信息
func (that *CooperClient) NewPayCfgAccountRequest() *PayCfgAccountRequest {
	return &PayCfgAccountRequest{
		Request: Request{
			Client:            that,
			publicParamsSlice: []string{
				//...
			},
			apiAddress: "/pay/cfgAccount",
		},
	}
}

//PayCfgAccountRequest
type PayCfgAccountRequest struct {
	Request
}

//Params ...
func (that *PayCfgAccountRequest) 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 PayCfgAccountResponse struct {
	CateId      int64                `json:"t_cate_id"`
	CatePid     int64                `json:"t_cate_pid"`
	CateName    string               `json:"t_cate_name"`
	AccountList []*PayCfgAccountList `json:"account_list"`
}

type PayCfgAccountList struct {
	ConfigId    int64  `json:"t_config_id"`
	TTypeId     int64  `json:"t_type_id"`
	AccountName string `json:"account_name"`
}

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