import { sanitizeJobId } from '../../../shared/services/mcpJobContext.js';
function buildPendingId(jobId) {
    return `pending-${sanitizeJobId(jobId)}`;
}
export class GateClaudeInvocationUseCase {
    deps;
    constructor(deps) {
        this.deps = deps;
    }
    async execute(input) {
        const { triggerMode, pendingReviewRequestGateway, enqueue, broadcastPendingChanged, logger } = this.deps;
        if (triggerMode === 'full-auto') {
            const enqueued = await enqueue(input.job, input.processor);
            if (!enqueued) {
                logger.info({ jobId: input.job.id }, 'Job rejected by queue (deduplicated or already active)');
                return { status: 'rejected', reason: 'Queue refused the job (deduplicated or already active)' };
            }
            return { status: 'enqueued', jobId: input.job.id };
        }
        const pendingId = buildPendingId(input.job.id);
        const createdAt = (this.deps.clock ?? (() => new Date()))().toISOString();
        const pending = {
            pendingReviewRequestId: pendingId,
            job: input.job,
            jobType: input.job.jobType ?? 'review',
            platform: input.job.platform,
            triggerSource: input.triggerSource,
            createdAt,
        };
        await pendingReviewRequestGateway.save(pending);
        broadcastPendingChanged(pending);
        logger.info({ pendingId, jobId: input.job.id, triggerSource: input.triggerSource }, 'Review parked for human confirmation (semi-auto trigger mode)');
        return { status: 'pending', pendingId };
    }
}
//# sourceMappingURL=gateClaudeInvocation.usecase.js.map