package logic

import (
	"app.yhyue.com/moapp/jybase/common"
	"context"
	"jyBXCore/rpc/type/bxcore"
	"net/http"

	"jyBXCore/api/internal/svc"
	"jyBXCore/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ParticipateSetUpInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
	r      *http.Request
}

func NewParticipateSetUpInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext, r *http.Request) *ParticipateSetUpInfoLogic {
	return &ParticipateSetUpInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
		r:      r,
	}
}

func (l *ParticipateSetUpInfoLogic) ParticipateSetUpInfo(req *types.ParticipateSetUpInfoReq) (resp *types.CommonResp, err error) {
	defer common.Catch()
	var (
		bidType    []*bxcore.BidTypeReq
		remindRule []*bxcore.RemindRuleReq
	)
	if req.SetAction != "" {
		if len(req.BidType) > 0 {
			for _, v := range req.BidType {
				bidType = append(bidType, &bxcore.BidTypeReq{
					Name:    v.Name,
					Content: v.Content,
				})
			}
		}
		if len(req.RemindRule) > 0 {
			for _, v := range req.RemindRule {
				remindRule = append(remindRule, &bxcore.RemindRuleReq{
					BidState:  v.BidState,
					Remainder: v.Remainder,
					Node:      v.Node,
				})
			}
		}
	}
	res, err := l.svcCtx.BxCore.ParticipateSetUpInfo(l.ctx, &bxcore.ParticipateSetUpInfoReq{
		EntId:        req.EntId,
		EntUserId:    req.EntUserId,
		PositionId:   req.PositionId,
		PositionType: req.PositionType,
		AppId:        req.AppId,
		UserId:       req.UserId,
		NewUserId:    req.NewUserId,
		AccountId:    req.AccountId,
		SetAction:    req.SetAction,
		IsAllow:      req.IsAllow,
		BidType:      bidType,
		RemindRule:   remindRule,
		EntAccountId: req.EntAccountId,
		Phone:        req.Phone,
		MgoUserId:    req.MgoUserId,
	})
	if err != nil {
		return &types.CommonResp{
			Err_code: -1,
			Err_msg:  "操作失败",
			Data:     false,
		}, nil
	}
	return &types.CommonResp{
		Err_code: res.ErrCode,
		Err_msg:  res.ErrMsg,
		Data:     res.Data,
	}, nil
}
