import { PatchBuilder } from '../PatchBuilder.ts';
import type Patch from '../../types/Patch.ts';
import type { TickReceipt } from '../../types/TickReceipt.ts';
import type { WarpState } from '../JoinReducer.ts';
import type { HashablePayload } from '../../types/conflict/HashablePayload.ts';
import type { StrandDescriptor, StrandQueuedIntent } from './strandTypes.ts';
import type PatchJournalPort from '../../../ports/PatchJournalPort.ts';
import type LoggerPort from '../../../ports/LoggerPort.ts';
import type BlobStoragePort from '../../../ports/BlobStoragePort.ts';
import type GraphPersistencePort from '../../../ports/GraphPersistencePort.ts';
import { type default as CommitMessageCodecPort } from '../../../ports/CommitMessageCodecPort.ts';
export type CommittedPatchResult = {
    patch: Patch;
    sha: string;
};
export type PatchCommitSuccessHandler = (result: CommittedPatchResult) => Promise<void>;
type WarpRuntime = {
    _graphName: string;
    _persistence: GraphPersistencePort;
    _patchInProgress: boolean;
    _maxObservedLamport: number;
    _stateDirty: boolean;
    _cachedViewHash: string | null;
    _cachedCeiling: number | null;
    _cachedFrontier: Map<string, string> | null;
    _cachedState: WarpState | null;
    _patchJournal: PatchJournalPort | null | undefined;
    _patchBlobStorage: BlobStoragePort | null | undefined;
    _blobStorage: BlobStoragePort | null | undefined;
    _commitMessageCodec: CommitMessageCodecPort;
    _logger: LoggerPort | null | undefined;
    _codec: {
        encode(v: HashablePayload): Uint8Array;
    };
    _onDeleteWithData: 'reject' | 'cascade' | 'warn';
};
type ServiceOptions = {
    graph: WarpRuntime;
    loadStrandOrThrow: (strandId: string) => Promise<StrandDescriptor>;
    materializeDescriptor: (descriptor: StrandDescriptor, options: {
        collectReceipts: boolean;
        ceiling: number | null;
    }) => Promise<{
        state: WarpState;
        receipts?: TickReceipt[];
        allPatches: Array<{
            patch: Patch;
            sha: string;
        }>;
    }>;
    writeDescriptor: (descriptor: StrandDescriptor) => Promise<void>;
    buildOverlayRef: (strandId: string) => string;
    buildIntentId: (strandId: string, sequence: number) => string;
};
export default class StrandPatchService {
    private readonly _graph;
    private readonly _loadStrandOrThrow;
    private readonly _materializeDescriptor;
    private readonly _writeDescriptor;
    private readonly _buildOverlayRef;
    private readonly _buildIntentId;
    /**
     * Create a patch/commit boundary over strand overlay writes and queued intent construction.
     */
    constructor({ graph, loadStrandOrThrow, materializeDescriptor, writeDescriptor, buildOverlayRef, buildIntentId, }: ServiceOptions);
    /**
     * Create a fluent patch builder wired to the strand's overlay ref.
     */
    createPatchBuilder(strandId: string): Promise<PatchBuilder>;
    /**
     * Build and commit a patch within a reentrancy guard.
     */
    patch(strandId: string, build: (p: PatchBuilder) => void | Promise<void>): Promise<string>;
    /**
     * Build a queued intent from a descriptor and user-supplied build callback.
     */
    buildQueuedIntent(descriptor: StrandDescriptor, build: (p: PatchBuilder) => void | Promise<void>): Promise<StrandQueuedIntent>;
    /**
     * Update the strand descriptor and graph caches after a successful overlay commit.
     */
    syncOverlayDescriptor(descriptor: StrandDescriptor, { patch, sha }: CommittedPatchResult): Promise<void>;
    /**
     * Encode, persist, and commit a single queued patch to the overlay chain.
     */
    commitQueuedPatch({ strandId, overlayId, parentSha, patch, contentBlobOids, lamport, }: {
        strandId: string;
        overlayId: string;
        parentSha: string | null;
        patch: Patch;
        contentBlobOids: string[];
        lamport: number;
    }): Promise<{
        sha: string;
        patch: Patch;
    }>;
    private _createPatchBuilderForDescriptor;
    private _buildPatchBuilderOptions;
    private _assertWritableDescriptor;
    private _buildQueuedIntentBuilder;
    private _freezeQueuedIntent;
    private _writeCommittedPatchBlob;
    private _resolveCommittedPatchStorage;
    private _buildPatchTreeEntries;
    private _commitPatchTree;
    private _attachOptionalPatchBuilderDeps;
    private _buildOverlayPatchBuilderOptions;
    private _attachOptionalPatchJournal;
    private _attachOptionalCommitMessageCodec;
    private _attachOptionalLogger;
    private _attachOptionalBlobStorage;
}
export {};
