/**
 * @fileoverview Centralized resource cleanup manager.
 *
 * Tracks timers, intervals, watchers, and other resources that need explicit
 * cleanup. Provides a unified dispose() method that safely cleans up all
 * registered resources, even on partial failures.
 *
 * @module utils/cleanup-manager
 */
import type { Disposable, CleanupRegistration, CleanupResourceType } from '../types.js';
/**
 * Options for setTimeout/setInterval with automatic cleanup.
 */
interface TimerOptions {
    /** Human-readable description for debugging */
    description?: string;
}
/**
 * Centralized manager for tracking and disposing resources.
 *
 * Implements the Disposable interface for hierarchical cleanup.
 * All registered resources are cleaned up when dispose() is called.
 *
 * Features:
 * - Tracks timers, intervals, watchers, and custom cleanup functions
 * - isStopped guard to prevent callbacks firing after disposal
 * - Safe disposal that continues even if individual cleanups fail
 * - Debug logging for resource tracking
 *
 * @example
 * ```typescript
 * class MyService implements Disposable {
 *   private cleanup = new CleanupManager();
 *
 *   start() {
 *     // Timer automatically cleared on dispose
 *     this.cleanup.setTimeout(() => {
 *       if (this.cleanup.isStopped) return;  // Guard
 *       this.doWork();
 *     }, 5000, { description: 'work timer' });
 *   }
 *
 *   dispose() {
 *     this.cleanup.dispose();
 *   }
 *
 *   get isDisposed() { return this.cleanup.isDisposed; }
 * }
 * ```
 */
export declare class CleanupManager implements Disposable {
    private registrations;
    private _isDisposed;
    private readonly debugMode;
    /**
     * Creates a new CleanupManager.
     *
     * @param debug - Enable debug logging for resource tracking
     */
    constructor(debug?: boolean);
    /**
     * Whether this manager has been disposed.
     * Check this before executing callbacks to prevent zombie operations.
     */
    get isDisposed(): boolean;
    /**
     * Alias for isDisposed - check before executing async callbacks.
     */
    get isStopped(): boolean;
    /**
     * Number of currently registered resources.
     */
    get resourceCount(): number;
    /**
     * Get counts by resource type for metrics/debugging.
     */
    get resourceCounts(): Record<CleanupResourceType, number>;
    /**
     * Schedule a timeout that will be automatically cleared on dispose.
     *
     * @param callback - Function to call when timeout fires
     * @param delay - Delay in milliseconds
     * @param options - Optional configuration
     * @returns Timer ID for manual clearing if needed
     */
    setTimeout(callback: () => void, delay: number, options?: TimerOptions): string;
    /**
     * Schedule an interval that will be automatically cleared on dispose.
     *
     * @param callback - Function to call on each interval
     * @param delay - Interval in milliseconds
     * @param options - Optional configuration
     * @returns Interval ID for manual clearing if needed
     */
    setInterval(callback: () => void, delay: number, options?: TimerOptions): string;
    /**
     * Register a custom cleanup function.
     *
     * @param type - Type of resource for categorization
     * @param cleanup - Function to call on dispose
     * @param description - Human-readable description
     * @returns Registration ID for manual removal if needed
     */
    registerCleanup(type: CleanupResourceType, cleanup: () => void, description: string): string;
    /**
     * Register a file system watcher for cleanup.
     *
     * @param watcher - Object with close() method (FSWatcher, chokidar, etc.)
     * @param description - Human-readable description
     * @returns Registration ID
     */
    registerWatcher(watcher: {
        close: () => void;
    }, description: string): string;
    /**
     * Register an event listener for cleanup.
     *
     * @param emitter - Object with removeListener/off method
     * @param event - Event name
     * @param listener - Listener function
     * @param description - Human-readable description
     * @returns Registration ID
     */
    registerListener<T extends {
        removeListener?: (event: string, listener: () => void) => void;
        off?: (event: string, listener: () => void) => void;
    }>(emitter: T, event: string, listener: () => void, description: string): string;
    /**
     * Register a stream for cleanup.
     *
     * @param stream - Object with destroy() or close() method
     * @param description - Human-readable description
     * @returns Registration ID
     */
    registerStream(stream: {
        destroy?: () => void;
        close?: () => void;
    }, description: string): string;
    /**
     * Manually remove a registered resource.
     *
     * @param id - Registration ID returned from register methods
     * @returns True if resource was found and removed
     */
    unregister(id: string): boolean;
    /**
     * Dispose all registered resources.
     * Safe to call multiple times (idempotent).
     * Continues cleanup even if individual resources fail.
     */
    dispose(): void;
    /**
     * Get all current registrations for debugging.
     */
    getRegistrations(): CleanupRegistration[];
    /**
     * Internal: Register a cleanup entry.
     */
    private register;
    /**
     * Internal: Debug logging.
     */
    private debug;
}
export {};
//# sourceMappingURL=cleanup-manager.d.ts.map