const ALREADY_RUNNING_MESSAGE = 'Cette review est déjà en cours';
export class ConfirmPendingReviewUseCase {
    deps;
    constructor(deps) {
        this.deps = deps;
    }
    async execute(input) {
        const { pendingReviewRequestGateway, queuePort, enqueue, resolveProcessor, logger } = this.deps;
        const pending = await pendingReviewRequestGateway.load(input.pendingId);
        if (!pending) {
            return { status: 'not-found' };
        }
        if (queuePort.hasActiveJob(pending.job.id)) {
            logger.info({ pendingId: input.pendingId, jobId: pending.job.id }, 'Pending review confirm rejected: already running');
            return { status: 'already-running', message: ALREADY_RUNNING_MESSAGE };
        }
        const processor = resolveProcessor(pending);
        const job = pending.job;
        const enqueued = await enqueue(job, processor);
        if (!enqueued) {
            logger.warn({ pendingId: input.pendingId, jobId: job.id }, 'Pending review confirm refused by queue');
            return { status: 'already-running', message: ALREADY_RUNNING_MESSAGE };
        }
        await pendingReviewRequestGateway.delete(input.pendingId);
        logger.info({ pendingId: input.pendingId, jobId: job.id }, 'Pending review confirmed and enqueued');
        return { status: 'confirmed', jobId: job.id };
    }
}
//# sourceMappingURL=confirmPendingReview.usecase.js.map