/**
 * 核心服务接口sdk（golang版）
 *
 * @desc 啪啪运动 核心服务接口sdk
 * ---------------------------------------------------------------------
 * @author		unphp <unphp@qq.com>
 * @date		2018-12-18
 * @copyright	core-utils
 * ---------------------------------------------------------------------
 */

package pposRequest

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

//new...
func (that *PPOSClient) NewCfgCateInfo() *CfgCateInfoRequest {
	return &CfgCateInfoRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/cfg/cfgCate/info",
		},
	}
}

//Request...
type CfgCateInfoRequest struct {
	Request
	TradeTypeId int64 `json:"trade_type_id"` //业务小类ID,例如1201
}

func (that *CfgCateInfoRequest) SetTradeTypeId(value int64) *CfgCateInfoRequest {
	that.TradeTypeId = value
	return that
}

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

//Do ...
func (that *CfgCateInfoRequest) Do() (CfgCateInfoResponse, error) {
	_rs := CfgCateInfoResponse{}
	//
	_data, _err := that.Client.GetData(that.apiAddress, that)
	if _err != nil {
		return _rs, _err
	}
	//
	_sliceData, _ok := _data.(map[string]interface{})
	if !_ok {
		return _rs, errors.New(that.apiAddress + "请求响应格式不正确")
	}
	//
	err := json.Unmarshal([]byte(utils.ToString(_sliceData)), &_rs)
	if err != nil {
		return _rs, errors.New(that.apiAddress + "Umarshal failed!")
	}
	return _rs, nil
}
