package pposRequest

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

//new... 根据订单类型获取会员退订数量
func (that *PPOSClient) NewshopOrderMemberRefundNumRequest() *shopOrderMemberRefundNumRequest {
	return &shopOrderMemberRefundNumRequest{
		Request: Request{
			Client:            that,
			apiAddress:        "shop/order/memberRefundNum",
			publicParamsSlice: []string{},
		},
	}
}

//Request...
type shopOrderMemberRefundNumRequest struct {
	Request
}

//Params ...
func (that *shopOrderMemberRefundNumRequest) 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
}

func (that *shopOrderMemberRefundNumRequest) SetBusinessType(value int64) *shopOrderMemberRefundNumRequest {
	that.initParams()
	that.params.Set("business_type", utils.ToString(value))
	return that
}

func (that *shopOrderMemberRefundNumRequest) SetStartTime(value string) *shopOrderMemberRefundNumRequest {
	that.initParams()
	that.params.Set("start_time", utils.ToString(value))
	return that
}

func (that *shopOrderMemberRefundNumRequest) SetEndTime(value string) *shopOrderMemberRefundNumRequest {
	that.initParams()
	that.params.Set("end_time", utils.ToString(value))
	return that
}

//Do ...
func (that *shopOrderMemberRefundNumRequest) Do() (int64, error) {
	//
	_data, _err := that.Client.GetData(that.apiAddress, that)
	if _err != nil {
		return 0, _err
	}
	if !utils.IsNumeric(_data) {
		return 0, _err
	}
	_count := utils.ToInt64(_data)
	return _count, nil
}
