package pposRequest

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

//活动平台支付用户配置信息
func (that *PPOSClient) NewActivityPlatformMemberGetByMemberIdRequest() *ActivityPlatformMemberGetByMemberIdsRequest {
	return &ActivityPlatformMemberGetByMemberIdsRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/activityPlatform/order/payInfo",
			publicParamsSlice: []string{
				"member_id",
			},
		}}
}

type ActivityPlatformMemberGetByMemberIdsRequest struct {
	Request
}

//会员信息
type ActivityMemberGetResponse struct {
	MemberId       int64                `json:"member_id"`
	MiniOpenId     string               `json:"mini_open_id"`
	Name           string               `json:"name"`
	Phone          string               `json:"phone"`
	TConfigId      int64                `json:"t_config_id"`
	PlatformAmount int64                `json:"platform_amount,omitempty"`
	ProfitSharing  []*ProfitSharingList `json:"profit_sharing"`
}

//分账方案
type ProfitSharingList struct {
	PlayAuthId string `json:"play_auth_id"`
	Amount     int64  `json:"amount,omitempty"`
}

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

func (that *ActivityPlatformMemberGetByMemberIdsRequest) SetParentOrderNo(value int64) *ActivityPlatformMemberGetByMemberIdsRequest {
	that.initParams()
	that.params.Set("parent_order_no", utils.ToString(value))
	return that
}

func (that *ActivityPlatformMemberGetByMemberIdsRequest) SetPaymentWay(value int64) *ActivityPlatformMemberGetByMemberIdsRequest {
	that.initParams()
	that.params.Set("payment_way", utils.ToString(value))
	return that
}

//Params ...
func (that *ActivityPlatformMemberGetByMemberIdsRequest) 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 *ActivityPlatformMemberGetByMemberIdsRequest) Do() (*ActivityMemberGetResponse, error) {
	//返回data
	_data, _err := that.Client.GetData(that.apiAddress, that)
	if _err != nil {
		return nil, _err
	}
	//
	_info := new(ActivityMemberGetResponse)
	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())
	//}
	_byte, _ := json.Marshal(_data)
	_ = json.Unmarshal(_byte, &_info)
	return _info, nil
}
