package pposRequest

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

//获取微信用户未支付订单(场地检查)
func (that *PPOSClient) NewFieldWxFieldBuyPlanGetUnPaidOrder() *FieldWxFieldBuyPlanGetUnPaidOrderRequest {
	return &FieldWxFieldBuyPlanGetUnPaidOrderRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/field/wxFieldBuyPlan/getUnPaidOrder",
			publicParamsSlice: []string{
				"member_id",
			},
		}}
}

type FieldWxFieldBuyPlanGetUnPaidOrderRequest struct {
	Request
}

//Params ...
func (that *FieldWxFieldBuyPlanGetUnPaidOrderRequest) 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 *FieldWxFieldBuyPlanGetUnPaidOrderRequest) Do() (string, error) {
	//返回data
	_data, _err := that.Client.GetData(that.apiAddress, that)
	if _err != nil {
		return "", _err
	}
	switch value := _data.(type) {
	case []interface{}:
		return "", nil
	case map[string]interface{}:
		return utils.ToString(value["parent_order_no"]), nil
	}
	//返回结果
	return "", nil
}
