package pposRequest

import (
	"errors"
	"net/url"
)

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

type PlatformAliOrderAuditRefundRequest struct {
	Request
}

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

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

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

//退款原因
func (that *PlatformAliOrderAuditRefundRequest) SetRefundReason(value string) *PlatformAliOrderAuditRefundRequest {
	that.initParams()
	that.params.Set("refund_reason", value)
	return that
}

//审核流水号
func (that *PlatformAliOrderAuditRefundRequest) SetAuditTradeNo(value string) *PlatformAliOrderAuditRefundRequest {
	that.initParams()
	that.params.Set("audit_trade_no", value)
	return that
}

//申请退款的验证码，多个以逗号分割。
func (that *PlatformAliOrderAuditRefundRequest) SetValidateCodes(value string) *PlatformAliOrderAuditRefundRequest {
	that.initParams()
	that.params.Set("validate_codes", value)
	return that
}

//核销是否可退，1核销可退 其他或者不传则不可退
func (that *PlatformAliOrderAuditRefundRequest) SetConsumeCanRefund(value string) *PlatformAliOrderAuditRefundRequest {
	that.initParams()
	that.params.Set("consume_can_refund", value)
	return that
}

//扩展字段，例如用户手机号:{"mobile":"18611111111"}
func (that *PlatformAliOrderAuditRefundRequest) SetExtra(value string) *PlatformAliOrderAuditRefundRequest {
	that.initParams()
	that.params.Set("extra", value)
	return that
}

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