package pposRequest

import (
	"errors"
	"net/url"
)

//取消订单
func (that *PPOSClient) NewPlatformAliOrderRefundNoticeRequest() *PlatformAliOrderRefundNoticeRequest {
	return &PlatformAliOrderRefundNoticeRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/platform/aliOrder/refundNotice",
			publicParamsSlice: []string{
				"ali_trade_no",
				"out_trade_no",
				"refund_amount",
			},
		}}
}

type PlatformAliOrderRefundNoticeRequest struct {
	Request
}

//橙狮体育订单号
func (that *PlatformAliOrderRefundNoticeRequest) SetAliTradeNo(value string) *PlatformAliOrderRefundNoticeRequest {
	that.initParams()
	that.params.Set("ali_trade_no", value)
	return that
}

//合作方订单号
func (that *PlatformAliOrderRefundNoticeRequest) SetOutTradeNo(value string) *PlatformAliOrderRefundNoticeRequest {
	that.initParams()
	that.params.Set("out_trade_no", value)
	return that
}

//申请退款金额，单位元
func (that *PlatformAliOrderRefundNoticeRequest) SetRefundAmount(value string) *PlatformAliOrderRefundNoticeRequest {
	that.initParams()
	that.params.Set("refund_amount", value)
	return that
}

//退款状态，1退款成功、2退款失败
func (that *PlatformAliOrderRefundNoticeRequest) SetRefundStatus(value string) *PlatformAliOrderRefundNoticeRequest {
	that.initParams()
	that.params.Set("refund_status", value)
	return that
}

//退款流水号
func (that *PlatformAliOrderRefundNoticeRequest) SetSerialNo(value string) *PlatformAliOrderRefundNoticeRequest {
	that.initParams()
	that.params.Set("serial_no", value)
	return that
}

//退款失败原因
func (that *PlatformAliOrderRefundNoticeRequest) SetRefundFailedReason(value string) *PlatformAliOrderRefundNoticeRequest {
	that.initParams()
	that.params.Set("refund_failed_reason", value)
	return that
}

//扩展字段，例如券码
func (that *PlatformAliOrderRefundNoticeRequest) SetExtra(value string) *PlatformAliOrderRefundNoticeRequest {
	that.initParams()
	that.params.Set("extra", value)
	return that
}

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