import type Database from 'better-sqlite3';
import type { EnterpriseRepositoryScope } from './enterpriseRepository';
export type TraceProcessorLeaseMode = 'shared' | 'isolated';
export type TraceProcessorLeaseState = 'pending' | 'starting' | 'ready' | 'idle' | 'active' | 'draining' | 'released' | 'crashed' | 'restarting' | 'failed';
export type TraceProcessorHolderType = 'frontend_http_rpc' | 'agent_run' | 'report_generation' | 'metric_backfill' | 'manual_register';
export type FrontendHolderVisibility = 'visible' | 'hidden' | 'offline';
export interface TraceProcessorHolderTtlPolicy {
    heartbeatTtlMs: number;
    idleTtlMs: number;
}
export interface TraceProcessorHolderInput {
    holderType: TraceProcessorHolderType;
    holderRef: string;
    windowId?: string;
    frontendVisibility?: FrontendHolderVisibility;
    sessionId?: string;
    runId?: string;
    reportId?: string;
    metadata?: Record<string, unknown>;
}
export interface TraceProcessorLeaseRecord {
    id: string;
    tenantId: string;
    workspaceId: string;
    traceId: string;
    mode: TraceProcessorLeaseMode;
    state: TraceProcessorLeaseState;
    rssBytes: number | null;
    heartbeatAt: number | null;
    expiresAt: number | null;
    holderCount: number;
    holders: TraceProcessorHolderRecord[];
}
export interface TraceProcessorHolderRecord {
    id: string;
    leaseId: string;
    holderType: TraceProcessorHolderType;
    holderRef: string;
    windowId: string | null;
    heartbeatAt: number | null;
    expiresAt: number | null;
    createdAt: number;
    metadata: Record<string, unknown> | null;
}
export declare function resolveHolderTtlPolicy(holder: TraceProcessorHolderInput): TraceProcessorHolderTtlPolicy;
export declare class TraceProcessorLeaseStore {
    private readonly db;
    constructor(db?: Database.Database);
    close(): void;
    acquireHolder(scope: EnterpriseRepositoryScope, traceId: string, holder: TraceProcessorHolderInput, options?: {
        mode?: TraceProcessorLeaseMode;
        now?: number;
    }): TraceProcessorLeaseRecord;
    acquireHolderForLease(scope: EnterpriseRepositoryScope, leaseId: string, holder: TraceProcessorHolderInput, options?: {
        now?: number;
    }): TraceProcessorLeaseRecord;
    heartbeatHolder(scope: EnterpriseRepositoryScope, leaseId: string, holder: TraceProcessorHolderInput, now?: number): TraceProcessorLeaseRecord;
    releaseHolder(scope: EnterpriseRepositoryScope, leaseId: string, holderType: TraceProcessorHolderType, holderRef: string): TraceProcessorLeaseRecord;
    markStarting(scope: EnterpriseRepositoryScope, leaseId: string): TraceProcessorLeaseRecord;
    markReady(scope: EnterpriseRepositoryScope, leaseId: string): TraceProcessorLeaseRecord;
    markCrashed(scope: EnterpriseRepositoryScope, leaseId: string): TraceProcessorLeaseRecord;
    markRestarting(scope: EnterpriseRepositoryScope, leaseId: string): TraceProcessorLeaseRecord;
    markFailed(scope: EnterpriseRepositoryScope, leaseId: string): TraceProcessorLeaseRecord;
    beginDraining(scope: EnterpriseRepositoryScope, leaseId: string): TraceProcessorLeaseRecord;
    recordRss(scope: EnterpriseRepositoryScope, leaseId: string, rssBytes: number | null): TraceProcessorLeaseRecord;
    getLeaseById(scope: EnterpriseRepositoryScope, leaseId: string): TraceProcessorLeaseRecord | null;
    listLeases(scope: EnterpriseRepositoryScope, criteria?: {
        traceId?: string;
        states?: TraceProcessorLeaseState[];
    }): TraceProcessorLeaseRecord[];
    hasActiveHolders(scope: EnterpriseRepositoryScope, traceId: string): boolean;
    sweepExpired(now?: number): {
        holdersRemoved: number;
        leasesReleased: number;
    };
    private transition;
    private upsertHolder;
    private refreshLeaseActivityState;
    private findAcquirableTraceLease;
    private findTraceLeaseByStates;
    private mustGetLease;
    private countHolders;
    private holdersForLease;
    private mapLease;
}
export declare function getTraceProcessorLeaseStore(): TraceProcessorLeaseStore;
export declare function setTraceProcessorLeaseStoreForTests(store: TraceProcessorLeaseStore | null): void;
//# sourceMappingURL=traceProcessorLeaseStore.d.ts.map