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

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

//NewPayCfgListRequest ... /账户管理 - 列表
func (that *CooperClient) NewPayCfgListRequest() *PayCfgListRequest {
	return &PayCfgListRequest{
		Request: Request{
			Client:            that,
			publicParamsSlice: []string{
				//...
			},
			apiAddress: "/pay/cfgPayList",
		},
	}
}

//PayCfgListRequest
type PayCfgListRequest struct {
	Request
}

//大类
func (that *PayCfgListRequest) SetTCateId(value int64) *PayCfgListRequest {
	that.initParams()
	that.params.Set("t_cate_id", utils.ToString(value))
	return that
}

//小类
func (that *PayCfgListRequest) SetTTypeId(value int64) *PayCfgListRequest {
	that.initParams()
	that.params.Set("t_type_id", utils.ToString(value))
	return that
}

//状态：1有效 2无效
func (that *PayCfgListRequest) SetIsEnable(value int64) *PayCfgListRequest {
	that.initParams()
	that.params.Set("IsEnable", utils.ToString(value))
	return that
}

//页码
func (that *PayCfgListRequest) SetPage(value int64) *PayCfgListRequest {
	that.initParams()
	that.params.Set("page", utils.ToString(value))
	return that
}
func (that *PayCfgListRequest) SetSize(value int64) *PayCfgListRequest {
	that.initParams()
	that.params.Set("size", utils.ToString(value))
	return that
}

//Params ...
func (that *PayCfgListRequest) 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 PayCfgListResponse struct {
	Count int64         `json:"count"` //count
	List  []*PayCfgData `json:"list"`  //list
	Page  int64         `json:"page"`  //page
	Size  int64         `json:"size"`  //size
}

type PayCfgData struct {
	Id          int64  `json:"id"`
	TConfigId   int64  `json:"t_config_id"`
	TTypeName   string `json:"t_type_name"`
	TCateName   string `json:"t_cate_name"`
	AccountName string `json:"account_name"`
}

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