import { Effect } from 'effect';
import { type CellValue, type SelectionState } from '@bilig/protocol';
import type { EngineOp } from '@bilig/workbook';
import type { EdgeArena, EdgeSlice } from '../../edge-arena.js';
import type { EngineRuntimeState, SpillMaterialization, U32 } from '../runtime-state.js';
import { EngineMutationError } from '../errors.js';
type DerivedOp = Extract<EngineOp, {
    kind: 'upsertSpillRange' | 'deleteSpillRange' | 'upsertPivotTable' | 'deletePivotTable';
}>;
export interface SpillClearResult {
    readonly changedCellIndices: number[];
    readonly ownerCellIndex: number | undefined;
}
export interface EngineMutationSupportService {
    readonly beginMutationCollection: () => Effect.Effect<void, EngineMutationError>;
    readonly markInputChanged: (cellIndex: number, count: number) => Effect.Effect<number, EngineMutationError>;
    readonly markFormulaChanged: (cellIndex: number, count: number) => Effect.Effect<number, EngineMutationError>;
    readonly markVolatileFormulasChanged: (count: number) => Effect.Effect<number, EngineMutationError>;
    readonly markSpillRootsChanged: (cellIndices: readonly number[], count: number) => Effect.Effect<number, EngineMutationError>;
    readonly markPivotRootsChanged: (cellIndices: readonly number[], count: number) => Effect.Effect<number, EngineMutationError>;
    readonly markExplicitChanged: (cellIndex: number, count: number) => Effect.Effect<number, EngineMutationError>;
    readonly composeMutationRoots: (changedInputCount: number, formulaChangedCount: number) => Effect.Effect<U32, EngineMutationError>;
    readonly composeEventChanges: (recalculated: U32, explicitChangedCount: number) => Effect.Effect<U32, EngineMutationError>;
    readonly composeDisjointEventChanges: (recalculated: U32, explicitChangedCount: number) => Effect.Effect<U32, EngineMutationError>;
    readonly unionChangedSets: (...sets: Array<readonly number[] | U32>) => Effect.Effect<U32, EngineMutationError>;
    readonly composeChangedRootsAndOrdered: (changedRoots: readonly number[] | U32, ordered: U32, orderedCount: number) => Effect.Effect<U32, EngineMutationError>;
    readonly getChangedInputBuffer: () => Effect.Effect<U32, EngineMutationError>;
    readonly ensureCellTracked: (sheetName: string, address: string) => Effect.Effect<number, EngineMutationError>;
    readonly ensureCellTrackedByCoords: (sheetId: number, row: number, col: number) => Effect.Effect<number, EngineMutationError>;
    readonly clearOwnedSpill: (cellIndex: number) => Effect.Effect<number[], EngineMutationError>;
    readonly clearSpillForCell: (cellIndex: number) => Effect.Effect<SpillClearResult, EngineMutationError>;
    readonly materializeSpill: (cellIndex: number, arrayValue: {
        values: CellValue[];
        rows: number;
        cols: number;
    }) => Effect.Effect<SpillMaterialization, EngineMutationError>;
    readonly removeSheetRuntime: (sheetName: string, explicitChangedCount: number) => Effect.Effect<{
        changedInputCount: number;
        formulaChangedCount: number;
        explicitChangedCount: number;
    }, EngineMutationError>;
    readonly syncDynamicRanges: (formulaChangedCount: number) => Effect.Effect<number, EngineMutationError>;
    readonly resetMaterializedCellScratch: (expectedSize: number) => Effect.Effect<void, EngineMutationError>;
    readonly beginMutationCollectionNow: (options?: {
        readonly ensureScratch?: boolean;
    }) => void;
    readonly markInputChangedNow: (cellIndex: number, count: number) => number;
    readonly markFormulaChangedNow: (cellIndex: number, count: number) => number;
    readonly markVolatileFormulasChangedNow: (count: number) => number;
    readonly markSpillRootsChangedNow: (cellIndices: readonly number[], count: number) => number;
    readonly markPivotRootsChangedNow: (cellIndices: readonly number[], count: number) => number;
    readonly markExplicitChangedNow: (cellIndex: number, count: number) => number;
    readonly composeMutationRootsNow: (changedInputCount: number, formulaChangedCount: number) => U32;
    readonly composeEventChangesNow: (recalculated: U32, explicitChangedCount: number) => U32;
    readonly composeDisjointEventChangesNow: (recalculated: U32, explicitChangedCount: number) => U32;
    readonly unionChangedSetsNow: (...sets: Array<readonly number[] | U32>) => U32;
    readonly composeChangedRootsAndOrderedNow: (changedRoots: readonly number[] | U32, ordered: U32, orderedCount: number) => U32;
    readonly getChangedInputBufferNow: () => U32;
    readonly ensureCellTrackedNow: (sheetName: string, address: string) => number;
    readonly ensureCellTrackedByCoordsNow: (sheetId: number, row: number, col: number) => number;
    readonly clearOwnedSpillNow: (cellIndex: number) => number[];
    readonly clearSpillForCellNow: (cellIndex: number) => SpillClearResult;
    readonly materializeSpillNow: (cellIndex: number, arrayValue: {
        values: CellValue[];
        rows: number;
        cols: number;
    }) => SpillMaterialization;
    readonly removeSheetRuntimeNow: (sheetName: string, explicitChangedCount: number) => {
        changedInputCount: number;
        formulaChangedCount: number;
        explicitChangedCount: number;
    };
    readonly syncDynamicRangesNow: (formulaChangedCount: number) => number;
    readonly resetMaterializedCellScratchNow: (expectedSize: number) => void;
}
export declare function createEngineMutationSupportService(args: {
    readonly state: Pick<EngineRuntimeState, 'workbook' | 'strings' | 'formulas' | 'ranges'>;
    readonly edgeArena: EdgeArena;
    readonly reverseState: {
        reverseCellEdges: Array<EdgeSlice | undefined>;
        reverseRangeEdges: Array<EdgeSlice | undefined>;
    };
    readonly removeFormula: (cellIndex: number) => boolean;
    readonly rebindFormulasForSheet: (sheetName: string, formulaChangedCount: number, candidates?: readonly number[] | U32) => number;
    readonly getSelectionState: () => SelectionState;
    readonly setSelection: (sheetName: string, address: string) => void;
    readonly applyDerivedOp: (op: DerivedOp) => number[];
    readonly scheduleWasmProgramSync: () => void;
    readonly ensureRecalcScratchCapacity: (size: number) => void;
    readonly collectFormulaDependents: (entityId: number) => Uint32Array;
    readonly getVolatileFormulaCellIndices?: () => Iterable<number>;
    readonly getChangedInputEpoch: () => number;
    readonly setChangedInputEpoch: (next: number) => void;
    readonly getChangedInputSeen: () => U32;
    readonly setChangedInputSeen: (next: U32) => void;
    readonly getChangedInputBuffer: () => U32;
    readonly setChangedInputBuffer: (next: U32) => void;
    readonly getChangedFormulaEpoch: () => number;
    readonly setChangedFormulaEpoch: (next: number) => void;
    readonly getChangedFormulaSeen: () => U32;
    readonly setChangedFormulaSeen: (next: U32) => void;
    readonly getChangedFormulaBuffer: () => U32;
    readonly setChangedFormulaBuffer: (next: U32) => void;
    readonly getChangedUnionEpoch: () => number;
    readonly setChangedUnionEpoch: (next: number) => void;
    readonly getChangedUnionSeen: () => U32;
    readonly setChangedUnionSeen: (next: U32) => void;
    readonly getChangedUnion: () => U32;
    readonly setChangedUnion: (next: U32) => void;
    readonly getMutationRoots: () => U32;
    readonly setMutationRoots: (next: U32) => void;
    readonly getMaterializedCellCount: () => number;
    readonly setMaterializedCellCount: (next: number) => void;
    readonly getMaterializedCells: () => U32;
    readonly setMaterializedCells: (next: U32) => void;
    readonly getExplicitChangedEpoch: () => number;
    readonly setExplicitChangedEpoch: (next: number) => void;
    readonly getExplicitChangedSeen: () => U32;
    readonly setExplicitChangedSeen: (next: U32) => void;
    readonly getExplicitChangedBuffer: () => U32;
    readonly setExplicitChangedBuffer: (next: U32) => void;
    readonly getImpactedFormulaEpoch: () => number;
    readonly setImpactedFormulaEpoch: (next: number) => void;
    readonly getImpactedFormulaSeen: () => U32;
    readonly setImpactedFormulaSeen: (next: U32) => void;
    readonly getImpactedFormulaBuffer: () => U32;
    readonly setImpactedFormulaBuffer: (next: U32) => void;
}): EngineMutationSupportService;
export {};
