import { R as Result } from './types-Cgumy1N4.js';

/**
 * Batch processing utility for running DCMTK operations on multiple files.
 * Provides concurrency control and progress tracking.
 *
 * Note: Streaming APIs are not provided because DCMTK binaries operate on
 * complete files, not streams. For large file processing, use {@link batch}
 * to process files in parallel with concurrency control.
 *
 * @module utils/batch
 */

/**
 * Options for batch processing.
 */
interface BatchOptions<T> {
    /** Maximum number of concurrent operations. Defaults to 4. Min 1, max 64. */
    readonly concurrency?: number | undefined;
    /** Called after each item completes (success or failure). */
    readonly onProgress?: ((completed: number, total: number, result: Result<T>) => void) | undefined;
    /** AbortSignal for cancelling all remaining work. */
    readonly signal?: AbortSignal | undefined;
}
/**
 * Aggregated results from a batch operation.
 */
interface BatchResult<T> {
    /** Results in the same order as the input items. */
    readonly results: ReadonlyArray<Result<T>>;
    /** Number of successful operations. */
    readonly succeeded: number;
    /** Number of failed operations. */
    readonly failed: number;
}
/**
 * Processes items in parallel with concurrency control.
 *
 * Items are launched in order but may complete out of order. Results are
 * always returned in the same order as the input items. When the AbortSignal
 * fires, no new items are launched, but in-flight operations are allowed to
 * complete.
 *
 * @param items - Array of input items to process
 * @param operation - Async function to apply to each item, returning Result<T>
 * @param options - Batch processing options
 * @returns Aggregated results with success/failure counts
 *
 * @example
 * ```ts
 * import { batch, dcmconv, TransferSyntax } from 'dcmtk';
 *
 * const files = ['a.dcm', 'b.dcm', 'c.dcm'];
 * const results = await batch(
 *     files,
 *     file => dcmconv(file, `${file}.converted`, { transferSyntax: TransferSyntax.JPEG_LOSSLESS }),
 *     { concurrency: 2, onProgress: (done, total) => console.log(`${done}/${total}`) }
 * );
 * console.log(`Succeeded: ${results.succeeded}, Failed: ${results.failed}`);
 * ```
 */
declare function batch<TItem, TResult>(items: readonly TItem[], operation: (item: TItem) => Promise<Result<TResult>>, options?: BatchOptions<TResult>): Promise<BatchResult<TResult>>;

/**
 * Retry utility with exponential backoff for unreliable operations.
 *
 * @module utils/retry
 */

/**
 * Options for retry behavior.
 */
interface RetryOptions {
    /** Maximum number of attempts (including initial). Defaults to 3. */
    readonly maxAttempts?: number | undefined;
    /** Initial delay in milliseconds before first retry. Defaults to 1000. */
    readonly initialDelayMs?: number | undefined;
    /** Maximum delay in milliseconds. Defaults to 30000. */
    readonly maxDelayMs?: number | undefined;
    /** Backoff multiplier. Defaults to 2. */
    readonly backoffMultiplier?: number | undefined;
    /** Optional predicate to determine if a failed result should be retried. */
    readonly shouldRetry?: ((error: Error, attempt: number) => boolean) | undefined;
    /** AbortSignal for cancelling retries. */
    readonly signal?: AbortSignal | undefined;
    /** Called before each retry attempt. */
    readonly onRetry?: ((error: Error, attempt: number, delayMs: number) => void) | undefined;
}
/**
 * Retries an operation with exponential backoff.
 *
 * The operation is called up to `maxAttempts` times. On failure, the delay
 * before the next retry grows exponentially (with jitter) up to `maxDelayMs`.
 * An AbortSignal can cancel the retry loop between attempts.
 *
 * @param operation - Async function returning Result<T>
 * @param options - Retry options
 * @returns The first successful result, or the last failure
 *
 * @example
 * ```ts
 * import { retry, echoscu } from 'dcmtk';
 *
 * const result = await retry(
 *     () => echoscu({ host: 'pacs.hospital.org', port: 104 }),
 *     { maxAttempts: 5, initialDelayMs: 2000 }
 * );
 * ```
 */
declare function retry<T>(operation: () => Promise<Result<T>>, options?: RetryOptions): Promise<Result<T>>;

export { type BatchOptions, type BatchResult, type RetryOptions, batch, retry };
