import type { NodePgDatabase } from 'drizzle-orm/node-postgres';
import type { Redis } from 'ioredis';
import { type Config } from '../common/config.js';
import type { ID } from '../common/types.js';
/**
 * Dependencies for EscalationService
 *
 * Use these to inject dependencies for testing or custom configurations.
 * If not provided, defaults to global singletons for backward compatibility.
 */
export interface EscalationServiceDependencies {
    /** Drizzle database instance */
    database?: NodePgDatabase;
    /** Redis client instance */
    redis?: Redis;
    /** Application configuration */
    config?: Config;
}
export type EscalationStatus = 'pending' | 'acknowledged' | 'approved' | 'rejected' | 'timeout' | 'cancelled';
export interface EscalationRecord {
    id: ID;
    intentId: ID;
    tenantId: ID;
    reason: string;
    reasonCategory: 'trust_insufficient' | 'high_risk' | 'policy_violation' | 'manual_review' | 'constraint_escalate';
    escalatedTo: string;
    escalatedBy?: string;
    status: EscalationStatus;
    resolution?: {
        resolvedBy: string;
        resolvedAt: string;
        notes?: string;
    };
    timeout: string;
    timeoutAt: string;
    acknowledgedAt?: string;
    slaBreached: boolean;
    context?: Record<string, unknown>;
    metadata?: Record<string, unknown>;
    createdAt: string;
    updatedAt: string;
}
export interface CreateEscalationOptions {
    intentId: ID;
    tenantId: ID;
    reason: string;
    reasonCategory: EscalationRecord['reasonCategory'];
    escalatedTo: string;
    escalatedBy?: string;
    timeout?: string;
    context?: Record<string, unknown>;
    metadata?: Record<string, unknown>;
}
export interface ResolveEscalationOptions {
    resolvedBy: string;
    notes?: string;
}
export interface ListEscalationFilters {
    tenantId: ID;
    status?: EscalationStatus | EscalationStatus[];
    intentId?: ID;
    escalatedTo?: string;
    limit?: number;
    cursor?: ID;
    includeSlaBreached?: boolean;
}
/**
 * Escalation Service with PostgreSQL persistence and Redis caching
 */
export declare class EscalationService {
    private config;
    private redis;
    private db;
    private readonly cachePrefix;
    private readonly indexPrefix;
    private readonly cacheTtlSeconds;
    /**
     * Create a new EscalationService instance.
     *
     * @param deps - Optional dependencies for dependency injection.
     *               If not provided, uses global singletons (backward compatible).
     *
     * @example
     * // Default usage (backward compatible)
     * const service = new EscalationService();
     *
     * @example
     * // With dependency injection (for testing)
     * const service = new EscalationService({
     *   database: mockDb,
     *   redis: mockRedis,
     *   config: testConfig,
     * });
     */
    constructor(deps?: EscalationServiceDependencies);
    /**
     * Create a new escalation for an intent
     */
    create(options: CreateEscalationOptions): Promise<EscalationRecord>;
    /**
     * Get an escalation by ID
     */
    get(id: ID, tenantId?: ID): Promise<EscalationRecord | null>;
    /**
     * Get escalation by intent ID (most recent)
     */
    getByIntentId(intentId: ID, tenantId?: ID): Promise<EscalationRecord | null>;
    /**
     * List escalations with filters
     */
    list(filters: ListEscalationFilters): Promise<EscalationRecord[]>;
    /**
     * List pending escalations for a tenant (optimized with Redis index)
     */
    listPending(tenantId: ID, options?: {
        limit?: number;
        offset?: number;
    }): Promise<EscalationRecord[]>;
    /**
     * Acknowledge an escalation (SLA tracking)
     */
    acknowledge(id: ID, tenantId: ID, acknowledgedBy: string): Promise<EscalationRecord | null>;
    /**
     * Approve an escalation
     */
    approve(id: ID, tenantId: ID, options: ResolveEscalationOptions): Promise<EscalationRecord | null>;
    /**
     * Reject an escalation
     */
    reject(id: ID, tenantId: ID, options: ResolveEscalationOptions): Promise<EscalationRecord | null>;
    /**
     * Cancel an escalation
     */
    cancel(id: ID, tenantId: ID, options: ResolveEscalationOptions): Promise<EscalationRecord | null>;
    /**
     * Resolve an escalation (internal)
     */
    private resolve;
    /**
     * Update SLA breach rate and approval rate gauges for a tenant
     */
    private updateRateGauges;
    /**
     * Process timed out escalations
     */
    processTimeouts(): Promise<number>;
    /**
     * Get escalation history for an intent
     */
    getHistory(intentId: ID, tenantId?: ID): Promise<EscalationRecord[]>;
    /**
     * Check if an intent has a pending escalation
     */
    hasPendingEscalation(intentId: ID): Promise<boolean>;
    /**
     * Get SLA breach statistics for a tenant
     */
    getSlaStats(tenantId: ID, since?: Date): Promise<{
        total: number;
        breached: number;
        breachRate: number;
        avgResolutionTime: number;
    }>;
    /**
     * Update Redis indexes for fast lookups
     */
    private updateRedisIndexes;
    /**
     * Invalidate cache for an escalation
     */
    private invalidateCache;
    /**
     * Rebuild Redis indexes from PostgreSQL (for recovery/consistency)
     */
    rebuildIndexes(tenantId?: ID): Promise<{
        indexed: number;
    }>;
}
/**
 * Create a new escalation service instance with dependency injection.
 *
 * This is the preferred way to create services in production code
 * as it makes dependencies explicit and testable.
 *
 * @param deps - Optional dependencies. If not provided, uses global singletons.
 * @returns Configured EscalationService instance
 *
 * @example
 * // Default usage (backward compatible)
 * const service = createEscalationService();
 *
 * @example
 * // With custom dependencies
 * const service = createEscalationService({
 *   database: customDb,
 *   redis: customRedis,
 *   config: customConfig,
 * });
 */
export declare function createEscalationService(deps?: EscalationServiceDependencies): EscalationService;
//# sourceMappingURL=escalation.d.ts.map