package pposRequest

import (
	"errors"
	"log"
	"net/url"
	"time"
)

//NewOrderToOfflineRequest  线下支付 - 通知子系统（场地）
func (that *PPOSClient) NewOrderToOfflineRequest() *OrderToOfflineRequest {
	return &OrderToOfflineRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/field/wxFieldBuyPlan/orderToOffline",
		},
		publicParamsSlice: []string{
			"parent_order_no", //父订单号
		},
		bT: time.Now(),
	}
}

type OrderToOfflineRequest struct {
	Request
	publicParamsSlice []string  //必传参数名
	bT                time.Time //耗时时间
}

func (that *OrderToOfflineRequest) SetParentOrderNo(value string) *OrderToOfflineRequest {
	that.initParams()
	that.params.Set("parent_order_no", value)
	return that
}

//Params ...
func (that *OrderToOfflineRequest) Params() (url.Values, error) {
	that.initParams()
	_params := that.params
	//
	for _, _v := range that.publicParamsSlice {
		if _params.Get(_v) == "" {
			return nil, errors.New(that.apiAddress + "缺少参数:" + _v)
		}
	}
	return _params, nil
}

//Do ...
func (that *OrderToOfflineRequest) Do() (bool, error) {
	//返回data
	_, _err := that.Client.GetData(that.apiAddress, that)
	log.Println(that.apiAddress+" 耗时: ", time.Since(that.bT))
	if _err != nil {
		return false, _err
	}
	//
	return true, nil
}
