package pposRequest

import (
	"errors"
	"net/url"
)

func (that *PPOSClient) NewFieldWxFieldBuyPlanCheckSkusUsed() *FieldWxFieldBuyPlanCheckSkusUsedRequest {
	return &FieldWxFieldBuyPlanCheckSkusUsedRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/field/wxFieldBuyPlan/checkSkusUsed",
			publicParamsSlice: []string{
				"skus",
			},
		}}
}

type FieldWxFieldBuyPlanCheckSkusUsedRequest struct {
	Request
}

func (that *FieldWxFieldBuyPlanCheckSkusUsedRequest) SetSkus(value string) *FieldWxFieldBuyPlanCheckSkusUsedRequest {
	that.initParams()
	that.params.Set("skus", value) //skus，多个逗号隔开
	return that
}

//Params ...
func (that *FieldWxFieldBuyPlanCheckSkusUsedRequest) 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 *FieldWxFieldBuyPlanCheckSkusUsedRequest) Do() (bool, error) {
	//返回data
	_data, _err := that.Client.GetData(that.apiAddress, that)
	if _err != nil {
		return false, _err
	}
	_result, _ok := _data.(bool)
	if !_ok {
		return false, errors.New(that.apiAddress + "请求响应格式不正确,错误代码01")
	}
	//返回结果
	return _result, nil
}
