import type { LTEscalationRecord } from '../../types';
import type { CreateEscalationInput, ClaimResult } from './types';
export declare function createEscalation(input: CreateEscalationInput): Promise<LTEscalationRecord>;
/**
 * Atomic claim operation. Does NOT change status — "claimed" is implicit
 * via assigned_to + assigned_until > NOW().
 *
 * Conditions:
 * - status = 'pending' (not resolved/cancelled)
 * - Either: unassigned, expired claim, or same user (extension)
 *
 * Uses a CTE to capture the previous state so callers can detect extensions.
 */
export declare function claimEscalation(id: string, userId: string, durationMinutes?: number): Promise<ClaimResult | null>;
export declare function resolveEscalation(id: string, resolverPayload: Record<string, any>): Promise<LTEscalationRecord | null>;
/**
 * Bulk update priority for a set of escalations.
 * Only updates pending escalations.
 */
export declare function updateEscalationsPriority(ids: string[], priority: 1 | 2 | 3 | 4): Promise<number>;
/**
 * Get the distinct roles for a set of escalation IDs.
 * Used for permission validation before bulk operations.
 */
export declare function getEscalationRoles(ids: string[]): Promise<string[]>;
/**
 * Release a single escalation claim back to the available pool.
 * Only the assigned user (or superadmin via route) may release.
 */
export declare function releaseEscalation(id: string, userId: string): Promise<LTEscalationRecord | null>;
export declare function releaseExpiredClaims(): Promise<number>;
/**
 * Reassign an escalation to a different role.
 * Clears the current assignment so it becomes available to the new role.
 */
export declare function escalateToRole(id: string, targetRole: string): Promise<LTEscalationRecord | null>;
export declare function getEscalation(id: string): Promise<LTEscalationRecord | null>;
export declare function getEscalationsByTaskId(taskId: string): Promise<LTEscalationRecord[]>;
export declare function getEscalationsByWorkflowId(workflowId: string): Promise<LTEscalationRecord[]>;
export declare function updateEscalationMetadata(id: string, patch: Record<string, any>): Promise<LTEscalationRecord | null>;
export declare function enrichEscalationRouting(id: string, metadataPatch: Record<string, any>, workflowFields: {
    workflowType?: string;
    workflowId?: string;
    taskQueue?: string;
    taskId?: string;
}): Promise<LTEscalationRecord | null>;
export declare function getEscalationsByOriginId(originId: string): Promise<LTEscalationRecord[]>;
export declare function findByMetadata(key: string, value: string, status?: string, limit?: number, offset?: number): Promise<{
    escalations: LTEscalationRecord[];
    total: number;
}>;
/**
 * Atomic claim by metadata with inline RBAC.
 * The SQL WHERE clause enforces role membership — if the caller
 * doesn't have an allowed role, zero rows match and the claim
 * never happens. No pre-flight find, no TOCTOU.
 *
 * @param allowedRoles — roles the caller can claim (null = no filter / global access)
 * @returns `{ escalation, isExtension, candidatesExist }` or null
 */
export declare function claimByMetadata(key: string, value: string, userId: string, durationMinutes?: number, metadata?: Record<string, any>, allowedRoles?: string[] | null): Promise<(ClaimResult & {
    candidatesExist: number;
}) | null>;
export interface ResolveByMetadataResult {
    /** 'resolved' = done atomically. 'signal_required' = signal_id present, caller must signal. */
    outcome: 'resolved' | 'signal_required' | 'not_found';
    /** The resolved escalation (when outcome = 'resolved') */
    escalation?: LTEscalationRecord;
    /** Signal info (when outcome = 'signal_required') */
    signalId?: string;
    escalationId?: string;
    workflowId?: string;
    workflowType?: string;
    taskQueue?: string;
}
/**
 * Atomic resolve by metadata with signal guard.
 *
 * Single query, two outcomes:
 * 1. No signal_id → claim + resolve atomically. Returns { outcome: 'resolved', escalation }.
 * 2. signal_id present → resolve skipped. Returns { outcome: 'signal_required', signalId, escalationId, ... }
 *    so the caller can signal the workflow. conditionLT handles the rest.
 */
export declare function resolveByMetadataAtomic(key: string, value: string, userId: string, resolverPayload: Record<string, any>, metadata?: Record<string, any>, allowedRoles?: string[] | null): Promise<ResolveByMetadataResult>;
