import type { Hash } from '@ariestools/sdk';
import type { BoundWitness, Payload } from '@xyo-network/sdk';
import { LRUCache } from 'lru-cache';
import type { NamedDataLake, PayloadLocation } from '../../primitives/datalake/index.js';
import { PayloadLocator } from '../../primitives/datalake/index.js';
import type { HydrateFunction } from '../../utils/index.js';
/** Valid recursion depths for BoundWitness hydration. */
export type HydrationDepth = 0 | 1 | 2;
/** A function that validates and narrows an unknown value into a typed BoundWitness or hydrated tuple. */
export type ZodAsserter<T> = (value: unknown, assert: true) => T;
/** Parameters for BoundWitnessHydrator. */
export interface BoundWitnessHydratorParams<TBw extends BoundWitness, THydrated> {
    asBoundWitness: ZodAsserter<TBw>;
    asHydrated: ZodAsserter<THydrated>;
    cacheMax?: number;
    cacheTtl?: number;
    datalakes: readonly NamedDataLake[];
    /** Predicate used at maxDepth >= 2 to identify payloads that are themselves BoundWitnesses to recurse into. Defaults to isBoundWitness. */
    isNestedBoundWitness?: (payload: Payload) => payload is BoundWitness;
}
/**
 * Hydrates a BoundWitness (and its referenced payloads) from one or more datalakes,
 * tracking which datalake served each hash. Supports depth-2 recursion into nested BoundWitnesses.
 */
export declare class BoundWitnessHydrator<TBw extends BoundWitness, THydrated> {
    protected readonly asBoundWitness: ZodAsserter<TBw>;
    protected readonly asHydrated: ZodAsserter<THydrated>;
    protected readonly isNestedBoundWitness: (payload: Payload) => payload is BoundWitness;
    protected readonly locator: PayloadLocator;
    protected readonly payloadCache: LRUCache<Hash, Payload>;
    protected readonly sourceCache: LRUCache<Hash, string>;
    /**
     * @throws if `params.datalakes` is empty (propagated from PayloadLocator). Required at construction
     *   to fail fast on misconfig. The only zero-datalake hydrate calls that would succeed anyway are
     *   degenerate (maxDepth=0 or a BW with empty payload_hashes) — not load-bearing enough to justify
     *   loosening the guard. If lifecycle ordering ever requires construction before sources are wired,
     *   prefer adding an `addDatalake()` mutator over removing this assertion.
     */
    constructor(params: BoundWitnessHydratorParams<TBw, THydrated>);
    hydrate(input: Hash | TBw, maxDepth?: HydrationDepth, minDepth?: HydrationDepth): Promise<THydrated>;
    /**
     * Like hydrateWithProvenance, but queries every datalake for every hash and returns the full
     * list of sources per hash. Bypasses the single-source LRU caches so that a prior first-found
     * cache hit cannot suppress discovery of additional sources.
     */
    hydrateWithAllProvenance(input: Hash | TBw, maxDepth?: HydrationDepth, minDepth?: HydrationDepth): Promise<[THydrated, Map<Hash, PayloadLocation[]>]>;
    hydrateWithProvenance(input: Hash | TBw, maxDepth?: HydrationDepth, minDepth?: HydrationDepth): Promise<[THydrated, Map<Hash, string>]>;
    /** Returns an adapter compatible with HydratedCache. The context arg is ignored. */
    toHydrateFunction(): HydrateFunction<THydrated>;
    tryHydrate(input: Hash | TBw, maxDepth?: HydrationDepth): Promise<THydrated | undefined>;
    tryHydrateWithAllProvenance(input: Hash | TBw, maxDepth?: HydrationDepth): Promise<[THydrated, Map<Hash, PayloadLocation[]>] | undefined>;
    tryHydrateWithProvenance(input: Hash | TBw, maxDepth?: HydrationDepth): Promise<[THydrated, Map<Hash, string>] | undefined>;
    protected appendDirectPayloads(bw: TBw, sources: Map<Hash, string>, minDepth: HydrationDepth, orderedHashes: Set<Hash>, orderedPayloads: Payload[]): Promise<void>;
    protected appendDirectPayloadsAll(bw: TBw, sources: Map<Hash, PayloadLocation[]>, minDepth: HydrationDepth, orderedHashes: Set<Hash>, orderedPayloads: Payload[]): Promise<void>;
    protected appendNestedPayloads(sources: Map<Hash, string>, minDepth: HydrationDepth, orderedHashes: Set<Hash>, orderedPayloads: Payload[]): Promise<void>;
    protected appendNestedPayloadsAll(sources: Map<Hash, PayloadLocation[]>, minDepth: HydrationDepth, orderedHashes: Set<Hash>, orderedPayloads: Payload[]): Promise<void>;
    protected fetchByHash(hash: Hash, sources: Map<Hash, string>): Promise<Payload | undefined>;
    protected fetchByHashes(hashes: Hash[], sources: Map<Hash, string>): Promise<Map<Hash, Payload>>;
    /**
     * Exhaustive variant: bypasses both LRU caches and queries every datalake. The picked payload
     * (locations[0].payload) is the first in registration order; the DataLakeViewer's content-addressed
     * fetch guarantees all entries for a given hash are equivalent.
     */
    protected fetchByHashesAll(hashes: Hash[], sources: Map<Hash, PayloadLocation[]>): Promise<Map<Hash, Payload>>;
    protected hydrateInternal(input: Hash | TBw, maxDepth: HydrationDepth, minDepth: HydrationDepth): Promise<[THydrated, Map<Hash, string>]>;
    protected hydrateInternalAll(input: Hash | TBw, maxDepth: HydrationDepth, minDepth: HydrationDepth): Promise<[THydrated, Map<Hash, PayloadLocation[]>]>;
    protected resolveBoundWitness(input: Hash | TBw, sources: Map<Hash, string>): Promise<TBw>;
    protected resolveBoundWitnessAll(input: Hash | TBw, sources: Map<Hash, PayloadLocation[]>): Promise<TBw>;
}
//# sourceMappingURL=BoundWitnessHydrator.d.ts.map