package pposRequest

import (
	"errors"
	"net/url"
)

//取消订单
func (that *PPOSClient) NewPlatformAliOrderCancelRequest() *PlatformAliOrderCancelRequest {
	return &PlatformAliOrderCancelRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/platform/aliOrder/cancel",
			publicParamsSlice: []string{
				"ali_trade_no",
				"trade_no",
			},
		}}
}

type PlatformAliOrderCancelRequest struct {
	Request
}

func (that *PlatformAliOrderCancelRequest) SetAliTradeNo(value string) *PlatformAliOrderCancelRequest {
	that.initParams()
	that.params.Set("ali_trade_no", value)
	return that
}
func (that *PlatformAliOrderCancelRequest) SetTradeNo(value string) *PlatformAliOrderCancelRequest {
	that.initParams()
	that.params.Set("trade_no", value)
	return that
}

//Params ...
func (that *PlatformAliOrderCancelRequest) 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 *PlatformAliOrderCancelRequest) Do() (interface{}, error) {
	//返回data
	_data, _err := that.Client.GetData(that.apiAddress, that)
	if _err != nil {
		return nil, _err
	}
	return _data, nil
}
