/**
 * 核心服务接口sdk（golang版）
 *
 * @desc 啪啪运动 核心服务接口sdk
 * ---------------------------------------------------------------------
 * @author		tang <zhifu.tang@papa.com.cn>
 * @date		2024-01-18
 * @copyright	core-utils
 * ---------------------------------------------------------------------
 */

package pposRequest

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

//NewCfgPayGetAll 获取配置
func (that *PPOSClient) NewCfgPayGetAll() *CfgPayGetAllRequest {
	return &CfgPayGetAllRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/cfg/pay/getAll",
		},
	}
}

type CfgPayGetAllResponse struct {
	CompanyId  int64 `json:"company_id"`  //公司id
	BusinessId int64 `json:"business_id"` //中心id
	TCateId    int64 `json:"t_cate_id"`   //大类别id
	TTypeId    int64 `json:"t_type_id"`   //小类别id
	TConfigId  int64 `json:"t_config_id"` //配置id
	Status     int64 `json:"status"`      //状态
	UnitType   int64 `json:"unit_type"`   //收款单位类型 0中心 1营业点 2场馆 3赛事团队 4培训机构
}

//CfgPayGetAllRequest 业务类别
type CfgPayGetAllRequest struct {
	Request
}

//Params ...
func (that *CfgPayGetAllRequest) Params() (url.Values, error) {
	that.initParams()
	_params := that.params
	return _params, nil
}

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

func (that *CfgPayGetAllRequest) SetStatus(value int64) *CfgPayGetAllRequest {
	that.initParams()
	that.params.Set("status", utils.ToString(value))
	return that
}

//Do ...
func (that *CfgPayGetAllRequest) Do() ([]*CfgPayGetAllResponse, 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 + "请求响应格式不正确")
	}
	_rs := make([]*CfgPayGetAllResponse, 0)
	_str, _err := json.Marshal(_sliceData)
	if _err != nil {
		return _rs, errors.New(that.apiAddress + "Marshal failed!" + _err.Error())
	}
	_err = json.Unmarshal(_str, &_rs)
	if _err != nil {
		return _rs, errors.New(that.apiAddress + "Unmarshal failed!" + _err.Error())
	}
	return _rs, nil
}
