/**
 * 核心服务接口sdk（golang版）
 *
 * @desc 啪啪运动 核心服务接口sdk
 * ---------------------------------------------------------------------
 * @author		tang <tzf2273465837@126.com>
 * @date		2023-06-23
 * @copyright	core-utils
 * ---------------------------------------------------------------------
 */

package pposRequest

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

//NewCfgUmsPayGetBusinessInfo 根据对账标识code获取配置
func (that *PPOSClient) NewCfgUmsPayGetBusinessInfo() *CfgUmsPayGetBusinessInfo {
	return &CfgUmsPayGetBusinessInfo{
		Request: Request{
			Client:     that,
			apiAddress: "/cfg/umsPay/getBusinessInfo",
		},
	}
}

type CfgUmsPayGetBusinessInfoResponse struct {
	CompanyId  int64 `json:"company_id"`
	BusinessId int64 `json:"business_id"`
	StadiumId  int64 `json:"stadium_id"`
}

//CfgUmsPayGetBusinessInfo
type CfgUmsPayGetBusinessInfo struct {
	Request
}

func (that *CfgUmsPayGetBusinessInfo) SetTid(value string) *CfgUmsPayGetBusinessInfo {
	that.initParams()
	that.params.Set("mid", value) //多商户号
	return that
}

//Params ...
func (that *CfgUmsPayGetBusinessInfo) 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
}

//Do ...
func (that *CfgUmsPayGetBusinessInfo) Do() (map[string]*CfgUmsPayGetBusinessInfoResponse, error) {
	//
	_data, _err := that.Client.GetData(that.apiAddress, that)
	if _err != nil {
		return nil, _err
	}
	//返回结果
	_rs := map[string]*CfgUmsPayGetBusinessInfoResponse{}
	_byte, _err := json.Marshal(_data)
	if _err != nil {
		return nil, _err
	}
	_err = json.Unmarshal(_byte, &_rs)
	if _err != nil {
		return nil, errors.New(that.apiAddress + _err.Error())
	}
	//
	return _rs, nil
}
