/**
 * StrandCoordinator — thin coordinator implementing StrandCapability.
 *
 * Composes StrandDescriptorStore, StrandMaterializer, StrandPatchService,
 * and StrandIntentService. Owns lifecycle orchestration (create, braid,
 * get, list, drop) and delegates everything else to the sub-services.
 *
 * Replaces StrandService.js (dissolved, not split).
 */
import { createImmutableTickReceiptArraySnapshot, createImmutableWarpStateSnapshot } from '../ImmutableSnapshot.ts';
import { STRAND_SCHEMA_VERSION, STRAND_COORDINATE_VERSION, STRAND_OVERLAY_KIND } from './strandShared.ts';
import type StrandDescriptorStore from './StrandDescriptorStore.ts';
import type StrandMaterializer from './StrandMaterializer.ts';
import type StrandPatchService from './StrandPatchService.ts';
import type StrandIntentService from './StrandIntentService.ts';
import type CryptoPort from '../../../ports/CryptoPort.ts';
import type GraphPersistencePort from '../../../ports/GraphPersistencePort.ts';
import type { StrandDescriptor as ParsedStrandDescriptor } from '../../utils/parseStrandBlob.ts';
import type Patch from '../../types/Patch.ts';
import type { PatchBuilder } from '../PatchBuilder.ts';
import type { StrandDescriptor } from './strandTypes.ts';
import type { WarpState } from '../JoinReducer.ts';
import type { TickReceipt } from '../../types/TickReceipt.ts';
export { STRAND_SCHEMA_VERSION, STRAND_COORDINATE_VERSION, STRAND_OVERLAY_KIND };
/**
 * Structural description of the graph runtime as seen by the
 * coordinator's test seam. Keep narrow: the coordinator only reads
 * `getFrontier` off the wider runtime; everything else stays inside
 * the sub-services.
 */
export type StrandCoordinatorGraph = {
    getFrontier?: () => Promise<Map<string, string>>;
};
/** Dependencies for StrandCoordinator. */
export type StrandCoordinatorDeps = {
    graphName: string;
    maxObservedLamport: () => number;
    crypto: CryptoPort;
    persistence: GraphPersistencePort;
    descriptors: StrandDescriptorStore;
    materializer: StrandMaterializer;
    patches: StrandPatchService;
    intents: StrandIntentService;
    /** The full graph runtime, stored for test-seam access and forward compatibility. */
    graph?: StrandCoordinatorGraph;
};
/**
 * The two shapes `materialize` can return. Either a frozen
 * immutable WarpState alone, or a bundle carrying the state plus
 * the replay receipts when the caller requested them.
 */
type ImmutableWarpState = ReturnType<typeof createImmutableWarpStateSnapshot>;
type ImmutableReceiptArray = ReturnType<typeof createImmutableTickReceiptArraySnapshot>;
type MaterializedStrandResult = ImmutableWarpState | Readonly<{
    state: ImmutableWarpState;
    receipts: ImmutableReceiptArray;
}>;
type LiveMaterializedStrandResult = Readonly<{
    state: WarpState;
    receipts: readonly TickReceipt[];
}>;
type StrandPatchEntry = {
    patch: Patch;
    sha: string;
};
export default class StrandCoordinator {
    private readonly _deps;
    constructor(deps: StrandCoordinatorDeps);
    get _graph(): StrandCoordinatorGraph | undefined;
    get _descriptorStore(): StrandDescriptorStore;
    get _materializer(): StrandMaterializer;
    get _patchService(): StrandPatchService;
    get _intentService(): StrandIntentService;
    _buildRef(strandId: string): string;
    _buildOverlayRef(strandId: string): string;
    _buildBraidPrefix(strandId: string): string;
    _writeDescriptor(descriptor: StrandDescriptor): Promise<void>;
    _hydrateOverlayMetadata(descriptor: ParsedStrandDescriptor): Promise<StrandDescriptor>;
    _collectPatchEntries(descriptor: StrandDescriptor, options: {
        ceiling: number | null;
        parentBasis?: 'pinned' | 'live';
    }): Promise<StrandPatchEntry[]>;
    _materializeDescriptor(descriptor: StrandDescriptor, options: {
        collectReceipts: boolean;
        ceiling: number | null;
        parentBasis?: 'pinned' | 'live';
    }): ReturnType<StrandMaterializer['materializeDescriptor']>;
    _commitQueuedPatch(params: Parameters<StrandPatchService['commitQueuedPatch']>[0]): ReturnType<StrandPatchService['commitQueuedPatch']>;
    create(options?: {
        strandId?: string;
        lamportCeiling?: number | null;
        owner?: string | null;
        scope?: string | null;
        leaseExpiresAt?: string | null;
    }): Promise<StrandDescriptor>;
    braid(strandId: string, options?: {
        braidedStrandIds?: string[];
        writable?: boolean | null;
    }): Promise<StrandDescriptor>;
    get(strandId: string): Promise<StrandDescriptor | null>;
    list(): Promise<StrandDescriptor[]>;
    drop(strandId: string): Promise<boolean>;
    getOrThrow(strandId: string): Promise<StrandDescriptor>;
    materializeLiveState(strandId: string, options?: {
        receipts?: boolean;
        ceiling?: number | null;
    }): Promise<LiveMaterializedStrandResult>;
    materializeReadState(strandId: string, options?: {
        receipts?: boolean;
        ceiling?: number | null;
    }): Promise<LiveMaterializedStrandResult>;
    materialize(strandId: string, options?: {
        receipts?: boolean;
        ceiling?: number | null;
    }): Promise<MaterializedStrandResult>;
    private _readParentBasisFor;
    createPatchBuilder(strandId: string): Promise<PatchBuilder>;
    patch(strandId: string, build: (p: PatchBuilder) => void | Promise<void>): Promise<string>;
    getPatchEntries(strandId: string, options?: {
        ceiling?: number | null;
    }): Promise<StrandPatchEntry[]>;
    patchesFor(strandId: string, entityId: string, options?: {
        ceiling?: number | null;
    }): Promise<string[]>;
    queueIntent(strandId: string, build: (p: PatchBuilder) => void | Promise<void>): Promise<Awaited<ReturnType<StrandIntentService['queueIntent']>>>;
    listIntents(strandId: string): Promise<Awaited<ReturnType<StrandIntentService['listIntents']>>>;
    tick(strandId: string): Promise<Awaited<ReturnType<StrandIntentService['tick']>>>;
    private _assertStrandDoesNotExist;
    private _getFrontier;
}
