import type { NodePgDatabase } from 'drizzle-orm/node-postgres';
import type { Redis } from 'ioredis';
import { type Config } from './config.js';
import type { ID } from './types.js';
import { type OperationType, type OperationStatus } from '../db/schema/operations.js';
/**
 * Async operation structure
 */
export interface AsyncOperation {
    id: string;
    type: OperationType;
    status: OperationStatus;
    progress: {
        current: number;
        total: number;
    };
    result?: unknown;
    error?: string;
    metadata?: Record<string, unknown>;
    createdAt: Date;
    completedAt?: Date;
}
/**
 * Dependencies for OperationTrackerService
 */
export interface OperationTrackerDependencies {
    database?: NodePgDatabase;
    redis?: Redis;
    config?: Config;
}
/**
 * Options for creating an operation
 */
export interface CreateOperationOptions {
    type: OperationType;
    tenantId: ID;
    createdBy?: ID;
    metadata?: Record<string, unknown>;
    totalItems?: number;
}
/**
 * Operation Tracker Service
 *
 * Tracks async operations with progress updates and result storage.
 * Uses PostgreSQL for persistence and Redis for fast progress lookups.
 */
export declare class OperationTrackerService {
    private db;
    private redis;
    private config;
    private readonly cachePrefix;
    private readonly progressPrefix;
    private readonly cacheTtlSeconds;
    private readonly longPollTimeoutMs;
    constructor(deps?: OperationTrackerDependencies);
    /**
     * Create a new async operation
     */
    createOperation(options: CreateOperationOptions): Promise<string>;
    /**
     * Update operation progress
     */
    updateProgress(operationId: ID, current: number, total: number): Promise<void>;
    /**
     * Mark operation as completed
     */
    completeOperation(operationId: ID, result: unknown): Promise<void>;
    /**
     * Mark operation as failed
     */
    failOperation(operationId: ID, error: string): Promise<void>;
    /**
     * Get operation by ID
     */
    getOperation(operationId: ID, tenantId?: ID): Promise<AsyncOperation | null>;
    /**
     * Get operation with long-polling support
     *
     * If wait=true and operation is not completed, waits for completion
     * or timeout (whichever comes first).
     */
    getOperationWithWait(operationId: ID, tenantId?: ID, wait?: boolean, timeoutMs?: number): Promise<AsyncOperation | null>;
    /**
     * Get operation from database
     */
    private getOperationFromDb;
    /**
     * Get fast progress from Redis
     * Falls back to database if not in cache
     */
    getProgress(operationId: ID): Promise<{
        current: number;
        total: number;
        status: OperationStatus;
    } | null>;
    /**
     * Convert database row to AsyncOperation
     */
    private rowToOperation;
}
/**
 * Get or create the operation tracker service singleton
 */
export declare function getOperationTracker(): OperationTrackerService;
/**
 * Create a new operation tracker service instance
 */
export declare function createOperationTracker(deps?: OperationTrackerDependencies): OperationTrackerService;
/**
 * Create a new async operation
 */
export declare function createOperation(type: OperationType, tenantId: ID, metadata?: Record<string, unknown>): Promise<string>;
/**
 * Update operation progress
 */
export declare function updateProgress(operationId: ID, current: number, total: number): Promise<void>;
/**
 * Mark operation as completed
 */
export declare function completeOperation(operationId: ID, result: unknown): Promise<void>;
/**
 * Mark operation as failed
 */
export declare function failOperation(operationId: ID, error: string): Promise<void>;
/**
 * Get operation by ID
 */
export declare function getOperation(operationId: ID): Promise<AsyncOperation | null>;
//# sourceMappingURL=operation-tracker.d.ts.map