package pposRequest

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

func (that *PPOSClient) NewMemberCardGetInfoRequest() *MemberCardGetInfoRequest {
	return &MemberCardGetInfoRequest{
		Request: Request{
			Client:            that,
			apiAddress:        "/member/memberCard/businessGetInfo",
			publicParamsSlice: []string{},
		}}
}

type MemberCardGetInfoRequest struct {
	Request
}

func (that *MemberCardGetInfoRequest) SetCardID(memberCardID int64) *MemberCardGetInfoRequest {
	that.initParams()
	that.params.Set("member_card_id", utils.ToString(memberCardID))
	return that
}

//Params ...
func (that *MemberCardGetInfoRequest) 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 *MemberCardGetInfoRequest) Do() (*MemberCardInfo, error) {
	//返回data
	_data, _err := that.Client.GetData(that.apiAddress, that)
	if _err != nil {
		return nil, _err
	}
	//返回结果
	_rs := &MemberCardInfo{}
	if _err := that.ParseResponeMp(_rs, _data, false); _err != nil {
		return nil, errors.New(that.apiAddress + "接口内部调用异常:" + _err.Error())
	}
	return _rs, nil
}
