import { MaybeRef, WatchSource } from 'vue';
/**
 * Repeatedly executes an asynchronous query while tracking arguments, state transitions,
 * and result freshness.
 *
 * @remarks
 *
 * ### Typical usage
 *
 * ```ts
 * const args = ref({ id: 'item-1' });
 * const { data, pause, resume, lastError } = usePollingQuery(args, fetchItem, {
 *   minInterval: 5_000,
 *   minDelay: 250,
 * });
 * ```
 *
 * The composable polls `fetchItem` while `resume()`d. Whenever the `args` ref changes the current
 * request is aborted, the status becomes `'stale'`, and a new poll is scheduled after the optional
 * debounce period and the configured timing constraints. Results from older requests are ignored
 * through version tracking, ensuring consumers only observe the freshest payload.
 *
 * ### Timing behaviour
 *
 * - `minInterval` defines the minimum duration between the start times of consecutive polls.
 * - `minDelay` (optional) enforces a minimum wait time between a poll finishing and the next poll starting.
 * - After each poll completes, the next poll is scheduled `max(minInterval - elapsed, minDelay)` ms later.
 * - When arguments change, the next poll still respects both constraints while also honouring the debounce.
 *
 * ### Abort handling
 *
 * Each poll receives a dedicated `AbortSignal`. The signal is aborted when pausing, disposing
 * the scope, or when the arguments ref changes. Queries should surface aborts by listening to
 * the signal. Aborted requests may settle later; outdated results are discarded via version checks.
 *
 * ### Pause, resume, and callback control
 *
 * - `pause()` stops future polls, clears pending timeouts, and aborts in-flight requests.
 * - `resume()` is idempotent; it reactivates polling only when currently inactive.
 * - The callback receives a bound `pause()` helper for conditional pausing.
 *
 * ### Error handling
 *
 * Errors bubble into `lastError`; they reset on the next successful poll or when `resume()`
 * transitions from inactive to active. With `pauseOnError: true` the composable pauses automatically.
 *
 * ### Argument tracking
 *
 * - Initial state is `{ status: 'idle' }`.
 * - Argument changes mark the status `'stale'` when a prior result exists; otherwise it stays `'idle'`.
 * - A successful poll for the latest arguments marks the status `'synced'` and updates `value`.
 *
 * ### Request versioning and concurrency
 *
 * Each poll increments an internal version counter. Only the latest version updates shared state,
 * preventing stale results from overwriting fresh data. `maxInFlightRequests` limits concurrent
 * polls; values > 1 allow the next poll to begin even if aborted requests are still settling, while
 * still capping total concurrency to protect upstream services.
 *
 * ### Debouncing
 *
 * Use `debounce` to accumulate rapid argument changes. The status still transitions to `'stale'`
 * immediately, all running polls are aborted, and the new poll waits for the debounce window
 * (and the timing constraints) before executing.
 *
 * ### Options
 *
 * - `minInterval` — required; must be positive. Zero or negative disables polling (`resume()` no-op). Accepts refs.
 * - `minDelay` — optional delay after completion before the next poll may start. Accepts refs.
 * - `autoStart` — start in active mode (default `true`).
 * - `triggerOnResume` — run the callback immediately on `resume()` (default `false`).
 * - `pauseOnError` — automatically pauses when the callback throws (default `false`).
 * - `maxInFlightRequests` — maximum concurrent polls (default `1`).
 * - `debounce` — debounce window for argument changes in milliseconds (default `0`).
 *
 * ### Returns
 *
 * - `data` — readonly ref of `{ status, value }`.
 * - `lastError` — readonly ref of the latest error (or `null`).
 * - `isActive` — readonly ref indicating active polling.
 * - `inFlightCount` — readonly ref with the number of active requests.
 * - `pause()` and `resume()` controls.
 *
 * @typeParam Args - Arguments shape passed to the polling callback.
 * @typeParam Result - Result type produced by the polling callback.
 */
export declare function usePollingQuery<Args, Result>(args: WatchSource<Args>, queryFn: (args: Args, options: {
    signal: AbortSignal;
    pause: () => void;
}) => Promise<Result>, options: {
    minInterval: MaybeRef<number>;
    minDelay?: MaybeRef<number | undefined>;
    autoStart?: boolean;
    triggerOnResume?: boolean;
    pauseOnError?: boolean;
    maxInFlightRequests?: number;
    debounce?: number;
}): {
    data: Readonly<import('vue').Ref<{
        readonly status: "idle";
    } | {
        readonly status: "synced";
        readonly value: import('vue').DeepReadonly<Result>;
    } | {
        readonly status: "stale";
        readonly value: import('vue').DeepReadonly<Result>;
    }, {
        readonly status: "idle";
    } | {
        readonly status: "synced";
        readonly value: import('vue').DeepReadonly<Result>;
    } | {
        readonly status: "stale";
        readonly value: import('vue').DeepReadonly<Result>;
    }>>;
    lastError: Readonly<import('vue').Ref<Error | null, Error | null>>;
    isActive: Readonly<import('vue').Ref<boolean, boolean>>;
    inFlightCount: Readonly<import('vue').Ref<number, number>>;
    pause: () => void;
    resume: () => void;
};
