package pposRequest

import (
	"errors"
	"net/url"
)

func (that *PPOSClient) NewMemberMiddlePlatformMemberBaseInfoGetRequest() *memberMiddlePlatformMemberBaseInfoGetRequest {
	return &memberMiddlePlatformMemberBaseInfoGetRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/memberMiddlePlatform/member/getBaseInfo",
			publicParamsSlice: []string{
				"member_id",
			},
		}}
}

type memberMiddlePlatformMemberBaseInfoGetRequest struct {
	Request
}

//会员信息
type MemberBaseInfoGetResponse struct {
	CompanyId         	 int64  `json:"company_id"`
	UnitId         		 int64  `json:"unit_id"`
	MemberId          	 int64  `json:"member_id"`
	WxOpenId          	 string `json:"wx_open_id"`
	MiniOpenId        	 string `json:"mini_open_id"`
	Name              	 string `json:"name"`
	Phone             	 string `json:"phone"`
	Avatar            	 string `json:"avatar"`
	Sex               	 int64  `json:"sex"`
	Birthday          	 string `json:"birthday"`
	Address           	 string `json:"address"`
	Nationality       	 string `json:"nationality"`
	CredentialsType      int64  `json:"credentials_type"`
	CredentialsName      string  `json:"credentials_name"`
	CredentialsNumber    string `json:"credentials_number"`
	CredentialsStartDate string `json:"credentials_start_date"`
	CredentialsEndDate   string `json:"credentials_end_date"`
	Channel              int64  `json:"channel"`
	Status               int64  `json:"status"`
	Remark               string `json:"remark"`
	Operator             int64  `json:"operator"`
	MemberLevelId        int64  `json:"member_level_id"`
	AvatarUrl            string `json:"avatar_url"`
	MemberLevelStr       string `json:"member_level_str"`
}

func (that *Request) SetMemberId(memberId string) *Request {
	that.initParams()
	that.params.Set("member_id", memberId)
	return that
}

//Params ...
func (that *memberMiddlePlatformMemberBaseInfoGetRequest) 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 *memberMiddlePlatformMemberBaseInfoGetRequest) Do() (*MemberBaseInfoGetResponse, error) {
	//返回data
	_data, _err := that.Client.GetData(that.apiAddress, that)
	if _err != nil {
		return nil, _err
	}
	//
	_info := new(MemberBaseInfoGetResponse)
	if _b, _ok := _data.(bool); _ok && !_b {
		//会员不存在
		return _info, nil
	}
	_mp, _ok := _data.(map[string]interface{})
	if !_ok {
		return nil, errors.New(that.apiAddress + "请求响应格式不正确,错误代码01")
	}
	if _err := that.ParseResponeMp(_info, _mp, false); _err != nil {
		return nil, errors.New(that.apiAddress + "请求响应格式化异常:" + _err.Error())
	}
	//返回结果
	return _info, nil
}
