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

package pposRequest

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

//NewCfgTradeGetByIDs 获取配置
func (that *PPOSClient) NewCfgTradeGetByIDs() *CfgTradeGetByIDsRequest {
	return &CfgTradeGetByIDsRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/cfg/cfgTrade/getByIds",
		},
	}
}

type CfgTradeGetByIDsResponse struct {
	MpId          int64  `json:"mp_id"`
	TradeTypeId   int64  `json:"trade_type_id"`
	TradeTypeCode string `json:"trade_type_code"`
	TradeCateId   int64  `json:"trade_cate_id"`
	TradeTypeName string `json:"trade_type_name"`
	IsOrder       int64  `json:"is_order"`
	IsProtocol    int64  `json:"is_protocol"`
}

//CfgTradeGetByIDsRequest 业务类别
type CfgTradeGetByIDsRequest struct {
	Request
	TradeTypeIds string `json:"trade_type_ids"` //类别ID,例如 1201,1203
}

func (that *CfgTradeGetByIDsRequest) SetTradeTypeIds(value string) *CfgTradeGetByIDsRequest {
	that.TradeTypeIds = value
	return that
}

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

//Do ...
func (that *CfgTradeGetByIDsRequest) Do() ([]*CfgTradeGetByIDsResponse, 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 := []*CfgTradeGetByIDsResponse{}
	for _, _v := range _sliceData {
		_vData, _ok := _v.(map[string]interface{})
		if !_ok {
			return nil, errors.New(that.apiAddress + "请求响应格式不正确2")
		}
		_tmp := new(CfgTradeGetByIDsResponse)
		if _err := that.ParseResponeMp(_tmp, _vData); _err != nil {
			return nil, errors.New(that.apiAddress + "请求响应格式化异常:" + _err.Error())
		}
		_rs = append(_rs, _tmp)
	}
	//
	return _rs, nil
}
