package pposRequest

import (
	"errors"
	"net/url"
)

//会员积分点增加
func (that *PPOSClient) NewMemberPointAddByOrderRequest() *MemberPointAddByOrderRequest {
	return &MemberPointAddByOrderRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/member/point/addByOrder",
			publicParamsSlice: []string{
				"parent_order_no",
			},
		}}
}

type MemberPointAddByOrderRequest struct {
	Request
}

func (that *MemberPointAddByOrderRequest) SetParentOrderNo(value string) *MemberPointAddByOrderRequest {
	that.initParams()
	that.params.Set("parent_order_no", value) //（订单中心的支付总单），唯一
	return that
}

//Params ...
func (that *MemberPointAddByOrderRequest) 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 *MemberPointAddByOrderRequest) Do() (interface{}, error) {
	//返回data
	_data, _err := that.Client.GetData(that.apiAddress, that)
	if _err != nil {
		return nil, _err
	}
	//返回结果
	return _data, nil
}
