package pposRequest

import (
	"errors"
	"net/url"
)

//NewMemberCardBusinessGetsRequest 根据获取会员卡id获取信息
func (that *PPOSClient) NewMemberCardBusinessGetsRequest() *MemberCardBusinessGetsRequest {
	return &MemberCardBusinessGetsRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/member/memberCard/businessGets",
			publicParamsSlice: []string{
				"member_card_ids",
			},
		},
	}
}

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

func (that *MemberCardBusinessGetsRequest) SetMemberCardIds(value string) *MemberCardBusinessGetsRequest {
	that.initParams()
	that.params.Set("member_card_ids", value)
	return that
}

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

//Do ...
func (that *MemberCardBusinessGetsRequest) Do() ([]*MemberCardInfos, error) {
	//返回data
	_data, _err := that.Client.GetData(that.apiAddress, that)
	if _err != nil {
		return nil, _err
	}
	//返回结果
	_rs := []*MemberCardInfos{}
	_sliceData, _ok := _data.([]interface{})
	if !_ok {
		return nil, errors.New(that.apiAddress + "请求响应格式不正确,错误代码01")
	}
	for _, _v := range _sliceData {
		_vData, _ok := _v.(map[string]interface{})
		if !_ok {
			return nil, errors.New(that.apiAddress + "请求响应格式不正确,错误代码02")
		}
		_tmp := new(MemberCardInfos)
		if _err := that.ParseResponeMp(_tmp, _vData, false); _err != nil {
			return nil, errors.New(that.apiAddress + "请求响应格式化异常:" + _err.Error())
		}
		_rs = append(_rs, _tmp)
	}
	return _rs, nil
}
