package pposRequest

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

//NewMemberCardGetPayRecordRequest 获取会员卡支付流水
func (that *PPOSClient) NewMemberCardGetPayRecordRequest() *MemberCardGetPayRecordRequest {
	return &MemberCardGetPayRecordRequest{
		Request: Request{
			Client:            that,
			apiAddress:        "/member/memberCard/getPayRecord",
			publicParamsSlice: []string{},
		},
	}
}

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

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

//Params ...
func (that *MemberCardGetPayRecordRequest) 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 MemberCardGetPayRecordResponse struct {
	RecordId        int64  `json:"record_id"`
	MemberId        int64  `json:"member_id"`
	MemberCardId    int64  `json:"member_card_id"`
	OrderNo         string `json:"order_no"`
	Worth           string `json:"worth"`             //本次变动后实际价值
	GiveWorth       int64  `json:"give_worth"`        //剩余赠送价值
	TrueWorth       int64  `json:"true_worth"`        //剩余真实价值
	PayGiveWorth    int64  `json:"pay_give_worth"`    //本次消费赠送价值
	PayTrueWorth    int64  `json:"pay_true_worth"`    //本次消费真实价值
	PayWorthPrice   int64  `json:"pay_worth_price"`   //本次变动实际价格(结转金额)
	WorthPrice      int64  `json:"worth_price"`       //真实权益的实际价格
	CardType        int64  `json:"card_type"`         //卡类型:1=> 一卡通 2 => "金额",3 => "次数",4=> "期限"
	ValidityEndDate string `json:"validity_end_date"` //有效时长
	Name            string `json:"name"`              //卡名字
	CardLevelName   string `json:"card_level_name"`   //卡级别名字
	CardNo          string `json:"card_no"`           //卡编号
	Unit            string `json:"unit"`
}

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