package cooper

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

//阿里体育 - 接收类请求
func (that *CooperClient) NewAliSportsRequest() *AliSportsCarInRequest {
	return &AliSportsCarInRequest{
		Request: Request{
			Client:     that,
			apiAddress: "",
		},
	}
}

//签名校验
func (that *AliSportsCarInRequest) QiMenVerify() *AliSportsCarInRequest {
	that.apiAddress = "/aliSports/qiMenVerify"
	return that
}

//阿里体育 - 获取订场类产品的场地日历
func (that *AliSportsCarInRequest) ProductBookDaily() *AliSportsCarInRequest {
	that.apiAddress = "/aliSports/productBookDaily"
	return that
}

//阿里体育 - 获取订场类产品的场地矩阵
func (that *AliSportsCarInRequest) ProductBook() *AliSportsCarInRequest {
	that.apiAddress = "/aliSports/productBook"
	return that
}

//阿里体育 - 获取票券类产品的信息
func (that *AliSportsCarInRequest) ProductTicket() *AliSportsCarInRequest {
	that.apiAddress = "/aliSports/productTicket"
	return that
}

//创建订单
func (that *AliSportsCarInRequest) OrderCreate() *AliSportsCarInRequest {
	that.apiAddress = "/aliSports/stadiumsOrderCreate"
	return that
}

//阿里体育 - 取消未支付订单
func (that *AliSportsCarInRequest) OrderCancel() *AliSportsCarInRequest {
	that.apiAddress = "/aliSports/stadiumsOrderCancel"
	return that
}

//阿里体育 - 订单支付成功后
func (that *AliSportsCarInRequest) OrderPayNotice() *AliSportsCarInRequest {
	that.apiAddress = "/aliSports/stadiumsOrderNotify"
	return that
}

//阿里体育 - 用户发起退款时
func (that *AliSportsCarInRequest) OrderRefundCreate() *AliSportsCarInRequest {
	that.apiAddress = "/aliSports/stadiumsRefundCreate"
	return that
}

//阿里体育 - 退款成功时
func (that *AliSportsCarInRequest) OrderRefundNotify() *AliSportsCarInRequest {
	that.apiAddress = "/aliSports/stadiumsRefundNotify"
	return that
}

//
type AliSportsCarInRequest struct {
	Request
}

//SetPostParamsMap...
func (that *AliSportsCarInRequest) SetPostParamsMap(params utils.Mp) *AliSportsCarInRequest {
	that.initParams()
	for _k, _v := range params {
		if utils.IsNumeric(_v) {
			that.params.Set(_k, utils.ToString(_v, true))
		} else {
			that.params.Set(_k, utils.ToString(_v))
		}
	}
	return that
}

//SetDataParam...
func (that *AliSportsCarInRequest) SetDataParam(data string) *AliSportsCarInRequest {
	that.initParams()
	that.params.Set("data", data)
	return that
}

//SetAppSecretParam...
func (that *AliSportsCarInRequest) SetAppSecretParam(data string) *AliSportsCarInRequest {
	that.initParams()
	that.params.Set("app_secret", data)
	return that
}

//Params ...
func (that *AliSportsCarInRequest) 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 *AliSportsCarInRequest) Do() (interface{}, error) {
	if that.apiAddress == "" {
		return "", errors.New("接口不存在")
	}
	_data, _err := that.Client.Post(that.apiAddress, that)
	if _err != nil {
		return "", _err
	}
	return _data, nil
}
