package pposRequest

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

//NewCfgTradeGetById 业务类型详情(小类)
func (that *PPOSClient) NewCfgTradeGetById() *CfgTradeGetByIdRequest {
	return &CfgTradeGetByIdRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/cfg/cfgTrade/getById",
		},
	}
}

//CfgTradeGetByIdRequest ...
type CfgTradeGetByIdRequest struct {
	Request
	TradeTypeId string //例如：1201
}

func (that *CfgTradeGetByIdRequest) SetTradeTypeId(value interface{}) *CfgTradeGetByIdRequest {
	that.TradeTypeId = utils.ToString(value)
	return that
}

//Params ...
func (that *CfgTradeGetByIdRequest) Params() (url.Values, error) {
	that.initParams()
	_params := that.params
	_params.Set("trade_type_id", utils.ToString(that.TradeTypeId))
	return _params, nil
}

//Do ...
func (that *CfgTradeGetByIdRequest) Do() (*CfgTradeGetByIdResponse, error) {
	_data, _err := that.Client.GetData(that.apiAddress, that)
	if _err != nil {
		return nil, _err
	}
	//
	_sliceData, _ok := _data.(map[string]interface{})
	if !_ok {
		return nil, errors.New(that.apiAddress + "请求响应格式不正确")
	}
	//
	_tmp := new(CfgTradeGetByIdResponse)
	if _err := that.ParseResponeMp(_tmp, _sliceData); _err != nil {
		return nil, errors.New(that.apiAddress + "请求响应格式化异常:" + _err.Error())
	}
	//
	return _tmp, nil
}
