package logic

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"jyBXCore/rpc/internal/svc"
	"jyBXCore/rpc/service"
	"jyBXCore/rpc/type/bxcore"
	"jyBXCore/rpc/util"
)

type ParticipateActionLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewParticipateActionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ParticipateActionLogic {
	return &ParticipateActionLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 项目参标 终止参标 划转等动作 in:参标；out:终止参标；transfer:划转
func (l *ParticipateActionLogic) ParticipateAction(in *bxcore.ParticipateActionReq) (*bxcore.ParticipateActionRes, error) {
	var res = &bxcore.ParticipateActionRes{
		Data: true,
	}
	if msg := util.IsAllowedAccess(in.ActionType); msg != "" {
		res.ErrCode = -1
		res.ErrMsg = msg
		res.Data = false
	} else if err := service.ParticipateDo(in); err != nil {
		res.ErrCode = -1
		res.ErrMsg = err.Error()
		res.Data = false
	}
	return res, nil
}
