package radar

import (
	"context"

	"apps/backend/internal/logic/radarmap"
	"apps/backend/internal/module/radar/domain"
	"apps/backend/internal/svc"
	"apps/backend/internal/types"

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

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

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

func (l *UpdateOpportunityReviewStateLogic) UpdateOpportunityReviewState(req *types.ReviewStateReq) (resp *types.OpportunityPublic, err error) {
	uid, err := ownerUID(l.ctx)
	if err != nil {
		return nil, err
	}
	o, err := l.svcCtx.Radar.UpdateOpportunityReviewState(l.ctx, uid, req.Id, domain.ReviewStatePatch{
		State: req.State, RemovalReason: req.RemovalReason, RemovalNote: req.RemovalNote,
		DuplicateOpportunityID: req.DuplicateOpportunityId, RemovedBy: uid,
	})
	if err != nil {
		return nil, err
	}
	return radarmap.Opportunity(o), nil
}
