/**
 * Hierarchy Escalation Service
 *
 * Handles escalation routing when normal reporting chains are disrupted.
 * Workers can bypass their Team Leader and report directly to the
 * Orchestrator when escalation conditions are met.
 *
 * Escalation conditions:
 * - TL session does not exist (inactive/crashed)
 * - TL has not responded for 15 minutes
 * - Security-flagged task requiring direct escalation
 *
 * @module services/hierarchy/hierarchy-escalation
 */
import type { TeamMember } from '../../types/index.js';
import type { EventBusService } from '../event-bus/event-bus.service.js';
/** Reasons for escalation */
export type EscalationReason = 'tl_unresponsive' | 'tl_inactive' | 'security' | 'cross_team' | 'other';
/**
 * An escalation message sent when bypassing the normal chain.
 */
export interface EscalationMessage {
    /** Message type identifier */
    type: 'escalation';
    /** Task ID being escalated */
    taskId: string;
    /** Reason for the escalation */
    reason: EscalationReason;
    /** Human-readable explanation */
    message: string;
    /** Member ID of the Team Leader who should have handled this */
    originalAssignedTo: string;
    /** Session name of the member who escalated */
    escalatedBy: string;
    /** ISO timestamp of the escalation */
    timestamp: string;
}
/**
 * Result of an escalation check.
 */
export interface EscalationCheckResult {
    /** Whether escalation is needed */
    shouldEscalate: boolean;
    /** Reason for escalation (if applicable) */
    reason?: EscalationReason;
    /** Target session to route to (parent of the unresponsive node) */
    targetSession?: string;
    /** Target member ID */
    targetMemberId?: string;
}
/**
 * HierarchyEscalationService handles routing of messages when the normal
 * reporting chain is disrupted. It checks escalation conditions, routes
 * messages to parent nodes, and emits hierarchy:escalation events.
 *
 * Singleton pattern matching other Crewly services.
 */
export declare class HierarchyEscalationService {
    private static instance;
    /** Tracks TL last response times for unresponsive detection */
    private tlResponseTimes;
    /** Event bus reference for emitting events */
    private eventBus;
    /** Configurable unresponsive timeout (default 15 minutes) */
    private unresponsiveTimeoutMs;
    private constructor();
    /**
     * Get the singleton instance of HierarchyEscalationService.
     *
     * @returns The singleton instance
     */
    static getInstance(): HierarchyEscalationService;
    /**
     * Clear the singleton instance (for testing).
     */
    static clearInstance(): void;
    /**
     * Set the EventBusService reference for emitting events.
     *
     * @param eventBus - The EventBusService instance
     */
    setEventBus(eventBus: EventBusService): void;
    /**
     * Override the default unresponsive timeout (for testing).
     *
     * @param timeoutMs - Timeout in milliseconds
     */
    setUnresponsiveTimeout(timeoutMs: number): void;
    /**
     * Record that a Team Leader has responded (resets unresponsive timer).
     *
     * @param sessionName - The TL's session name
     */
    recordTLResponse(sessionName: string): void;
    /**
     * Check whether escalation conditions are met for a given worker.
     * Inspects the worker's Team Leader status and responsiveness.
     *
     * @param worker - The worker member attempting to report
     * @param allMembers - All team members for hierarchy traversal
     * @param securityFlag - Whether this is a security-flagged escalation
     * @returns Check result indicating if escalation is needed and where to route
     */
    checkEscalationConditions(worker: TeamMember, allMembers: TeamMember[], securityFlag?: boolean): EscalationCheckResult;
    /**
     * Route a message to the parent member in the hierarchy.
     * Traverses upward along the parentMemberId chain.
     *
     * @param member - The member whose parent to find
     * @param allMembers - All team members
     * @returns The parent member, or null if none exists
     */
    routeToParent(member: TeamMember, allMembers: TeamMember[]): TeamMember | null;
    /**
     * Handle an unresponsive Team Leader situation.
     * Finds the next available parent in the hierarchy and creates
     * an escalation message.
     *
     * @param tlSession - Session name of the unresponsive TL
     * @param worker - The worker who detected the issue
     * @param allMembers - All team members
     * @param taskId - Task ID being escalated
     * @param message - Human-readable escalation message
     * @param teamInfo - Team info for event emission
     * @returns The escalation message and target, or null if no escalation target
     */
    handleTLUnresponsive(tlSession: string, worker: TeamMember, allMembers: TeamMember[], taskId: string, message: string, teamInfo?: {
        teamId: string;
        teamName: string;
    }): {
        escalation: EscalationMessage;
        target: TeamMember;
    } | null;
    /**
     * Get the full escalation chain from a member up to root.
     * Returns members in order: [immediate parent, grandparent, ..., root].
     *
     * @param member - Starting member
     * @param allMembers - All team members
     * @returns Array of members from parent to root
     */
    getEscalationChain(member: TeamMember, allMembers: TeamMember[]): TeamMember[];
    /**
     * Clear all TL response records (for cleanup/testing).
     */
    clearResponseRecords(): void;
    /**
     * Find the parent member of a given member.
     */
    private findParent;
    /**
     * Find the root member (no parentMemberId) in the hierarchy.
     */
    private findRoot;
    /**
     * Check if a Team Leader has been unresponsive beyond the timeout.
     */
    private isTLUnresponsive;
}
//# sourceMappingURL=hierarchy-escalation.service.d.ts.map