/**
 * 核心服务接口sdk（golang版）
 *
 * @desc 啪啪运动 核心服务接口sdk
 * ---------------------------------------------------------------------
 * @author		logan <lgq092@163.com>
 * @date		2021-12-10
 * @copyright	core-utils
 * ---------------------------------------------------------------------
 */

package pposRequest

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

//new...
func (that *PPOSClient) NewCfgIposCfgGetCfg() *CfgIposCfgGetCfgRequest {
	return &CfgIposCfgGetCfgRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/cfg/iposPay/getCfg",
		},
	}
}

type CfgIposCfgGetCfgResponse struct {
	CompanyId  int64 `json:"company_id"`
	BusinessId int64 `json:"business_id"`
	TConfigId  int64 `json:"t_config_id"`
	UnitId     int64 `json:"unit_id"`
	UnitType   int   `json:"unit_type"`
	Status     int   `json:"status"`
}

//Request...
type CfgIposCfgGetCfgRequest struct {
	Request
}

func (that *CfgIposCfgGetCfgRequest) SetUnitType(value int64) *CfgIposCfgGetCfgRequest {
	that.initParams()
	that.params.Set("unit_type", utils.ToString(value))
	return that
}

func (that *CfgIposCfgGetCfgRequest) SetUnitId(value int64) *CfgIposCfgGetCfgRequest {
	that.initParams()
	that.params.Set("unit_id", utils.ToString(value))
	return that
}

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

//Do ...
func (that *CfgIposCfgGetCfgRequest) Do() (*CfgIposCfgGetCfgResponse, error) {
	//
	_data, _err := that.Client.GetData(that.apiAddress, that)
	if _err != nil {
		return nil, _err
	}

	_str, _err := json.Marshal(_data)
	//返回结果
	_rs := new(CfgIposCfgGetCfgResponse)
	_err = json.Unmarshal(_str, &_rs)
	if _err != nil {
		return _rs, errors.New(that.apiAddress + _err.Error())
	}
	return _rs, nil
}
