package pposRequest

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

//NewMemberCardGetPayBalanceRequest 获取会员卡余额
func (that *PPOSClient) NewMemberCardGetPayBalanceRequest() *MemberCardGetPayBalanceRequest {
	return &MemberCardGetPayBalanceRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/member/memberCard/getMemberCardBalance",
			publicParamsSlice: []string{
				"member_card_id",
			},
		},
	}
}

//
type MemberCardGetPayBalanceRequest struct {
	Request
	publicParamsSlice []string //必传参数名
}

func (that *MemberCardGetPayBalanceRequest) SetMemberCardId(value int64) *MemberCardGetPayBalanceRequest {
	that.initParams()
	that.params.Set("member_card_id", utils.ToString(value))
	return that
}

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

type MemberCardGetPayBalanceResponse struct {
	Worth int64 `json:"worth"` //本次变动后实际价值
}

//Do ...
func (that *MemberCardGetPayBalanceRequest) Do() (*MemberCardGetPayBalanceResponse, error) {
	_data, _err := that.Client.GetData(that.apiAddress, that)
	if _err != nil {
		return nil, _err
	}
	fmt.Println("+++++++++++请求结果++++++++++++", _data)
	_tmp := new(MemberCardGetPayBalanceResponse)
	if _err := that.ParseResponeMp(_tmp, _data, false); _err != nil {
		return nil, errors.New(that.apiAddress + "请求响应格式化异常:" + _err.Error())
	}
	return _tmp, nil
}
