package pposRequest

import (
	"net/url"
)

//NewGatewayCfgUpdate 更新网关的配置
func (that *PPOSClient) NewGatewayCfgUpdate() *GatewayCfgUpdateRequest {
	return &GatewayCfgUpdateRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/gateway/cfg/update",
		},
		mustParams: []string{
			"cfg_key",
			"cfg_type",
			"cfg_data",
		},
	}
}

//GateEnterRequest 业务类别
type GatewayCfgUpdateRequest struct {
	Request
	mustParams []string
}

func (that *GatewayCfgUpdateRequest) SetCfgKey(val string) *GatewayCfgUpdateRequest {
	that.initParams()
	_params := that.params
	_params.Set("cfg_key", val)
	return that
}

func (that *GatewayCfgUpdateRequest) SetCfgType(val string) *GatewayCfgUpdateRequest {
	that.initParams()
	_params := that.params
	_params.Set("cfg_type", val)
	return that
}

func (that *GatewayCfgUpdateRequest) SetCfgData(val string) *GatewayCfgUpdateRequest {
	that.initParams()
	_params := that.params
	_params.Set("cfg_data", val)
	return that
}

//Params ...
func (that *GatewayCfgUpdateRequest) Params() (url.Values, error) {
	that.initParams()
	return that.params, nil
}

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