/**
 * EscalateToUserUseCase
 *
 * Single shared entry point that other use cases call when they need to
 * surface a collaboration-fabric event (supervisor escalation, supervisor
 * failure, blocking question, …) to the user via the existing notification
 * channels and the immutable activity log.
 *
 * Behaviour:
 *
 *  1. Short-circuits when `featureFlags.collaboration` is off so NFR-14
 *     (byte-identical default behaviour) is preserved.
 *  2. Dispatches a single {@link NotificationEvent} via
 *     {@link INotificationService}. The notification service itself is
 *     responsible for honoring per-event preferences and per-channel
 *     enable/disable.
 *  3. Mirrors the escalation as an immutable {@link ActivityEntry} so the
 *     audit trail records who triggered it and what kind of escalation it
 *     was (supervisor:<id>, system, etc.).
 *
 * Centralising this logic keeps {@link AskAgentQuestionUseCase} and
 * {@link EvaluateSupervisorDecisionUseCase} thin — they each call this use
 * case rather than duplicating the notify + audit pair.
 */
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
import { inject, injectable } from 'tsyringe';
import { randomUUID } from 'node:crypto';
let EscalateToUserUseCase = class EscalateToUserUseCase {
    notifications;
    activityLog;
    settings;
    constructor(notifications, activityLog, settings) {
        this.notifications = notifications;
        this.activityLog = activityLog;
        this.settings = settings;
    }
    async execute(input) {
        if (!(await this.isCollaborationEnabled())) {
            return { escalated: false };
        }
        const now = input.timestamp ?? new Date();
        const event = {
            eventType: input.eventType,
            agentRunId: input.agentRunId,
            featureId: input.featureId,
            featureName: input.featureName,
            message: input.message,
            severity: input.severity,
            timestamp: now.toISOString(),
        };
        this.notifications.notify(event);
        const entry = {
            id: randomUUID(),
            workItemId: input.sourceEventId,
            fieldName: input.auditField,
            oldValue: undefined,
            newValue: input.eventType,
            actorId: input.actorId,
            createdAt: now,
            updatedAt: now,
        };
        await this.activityLog.create(entry);
        return { escalated: true };
    }
    async isCollaborationEnabled() {
        const settings = await this.settings.load();
        return settings?.featureFlags?.collaboration === true;
    }
};
EscalateToUserUseCase = __decorate([
    injectable(),
    __param(0, inject('INotificationService')),
    __param(1, inject('IActivityLogRepository')),
    __param(2, inject('ISettingsRepository')),
    __metadata("design:paramtypes", [Object, Object, Object])
], EscalateToUserUseCase);
export { EscalateToUserUseCase };
