// Operation log primitives — the generic, app-agnostic core of the sync engine.
export {
  OpType,
  isMultiEntityPayload,
  extractActionPayload,
  extractEntityFromPayload,
  extractUpdateChanges,
} from './operation.types';
export type {
  VectorClock,
  Operation,
  OperationLogEntry,
  EntityConflict,
  ConflictResult,
  EntityChange,
  MultiEntityPayload,
} from './operation.types';

// Vector-clock algorithms — single source of truth for client/server parity.
export {
  compareVectorClocks,
  mergeVectorClocks,
  limitVectorClockSize,
  MAX_VECTOR_CLOCK_SIZE,
} from './vector-clock';
export { VectorClockComparison } from './vector-clock';

// Full-state import clean-slate vector-clock decisions.
export { classifyOpAgainstSyncImport } from './sync-import-filter';

// Host-configured sync file prefix helpers.
export { createSyncFilePrefixHelpers } from './sync-file-prefix';
export type {
  SyncFilePrefixInvalidPrefixDetails,
  SyncFilePrefixParams,
  SyncFilePrefixParamsOutput,
} from './sync-file-prefix';

// Gzip compression helpers.
export {
  compressWithGzip,
  compressWithGzipToString,
  decompressGzipFromString,
} from './compression';

// Encryption primitives — Argon2id KDF + AES-GCM, Web Crypto with @noble fallback.
// See packages/sync-core/src/encryption.ts for the wire-format contract and
// the legacy-KDF warning side-channel.
export {
  encrypt,
  decrypt,
  encryptBatch,
  decryptBatch,
  deriveKeyFromPassword,
  clearSessionKeyCache,
  getSessionKeyCacheStats,
  getArgon2Params,
  isCryptoSubtleAvailable,
  setArgon2ParamsForTesting,
  setLegacyKdfWarningHandler,
} from './encryption';
export type { DerivedKey } from './encryption';

// Generic error helpers.
export { extractErrorMessage } from './error.util';
export { WebCryptoNotAvailableError } from './web-crypto-error';

// Full-state operation classification helper. Hosts supply their own op strings.
export { createFullStateOpTypeHelpers } from './full-state-op-types';
export type { FullStateOpTypeHelpers } from './full-state-op-types';

// LWW (Last-Writer-Wins) update action-type helpers — factory parameterized by
// the host application's entity-type list, so the lib stays domain-agnostic.
export { createLwwUpdateActionTypeHelpers } from './lww-update-action-types';
export type { LwwUpdateActionTypeHelpers } from './lww-update-action-types';

// Apply-operation result and option types.
export type { ApplyOperationsResult, ApplyOperationsOptions } from './apply.types';

// Generic operation replay coordinator.
export { replayOperationBatch } from './replay-coordinator';

// Remote operation application coordinator.
export { applyRemoteOperations } from './remote-apply';
export type {
  ApplyRemoteOperationsOptions,
  RemoteOperationApplyStorePort,
} from './remote-apply';

// Upload planning helpers.
export {
  planRegularOpsAfterFullStateUpload,
  planUploadLastServerSeqUpdate,
} from './upload-planning';

// Download planning helpers.
export {
  planDownloadFullStateUpload,
  planDownloadGapReset,
  planDownloadedDataEncryptionState,
  planSnapshotHydration,
} from './download-planning';

// Port contracts for app-side orchestration adapters.
export type {
  ActionDispatchPort,
  ArchiveSideEffectPort,
  ConflictUiDialogRequest,
  ConflictUiPort,
  DeferredLocalActionsPort,
  OperationApplyPort,
  RemoteApplyWindowPort,
  SyncActionLike,
} from './ports';

// Conflict-resolution helpers.
export {
  convertLocalDeleteRemoteUpdatesToLww,
  deepEqual,
  isIdenticalConflict,
  partitionLwwResolutions,
  planLwwConflictResolutions,
  suggestConflictResolution,
} from './conflict-resolution';
export type {
  ConflictResolutionSuggestion,
  EntityConflictLike,
  LwwConflictResolutionPlan,
  LwwResolvedConflict,
} from './conflict-resolution';

// Entity-frontier and clock-corruption helpers (per-entity vector-clock domain).
export { adjustForClockCorruption, buildEntityFrontier } from './entity-frontier';

// Entity-registry contracts.
export {
  getEntityConfig,
  getPayloadKey,
  isAdapterEntity,
  isSingletonEntity,
  isMapEntity,
  isArrayEntity,
  isVirtualEntity,
  getAllPayloadKeys,
} from './entity-registry.types';
export type {
  EntityStoragePattern,
  BaseEntity,
  EntityDictionary,
  EntityConfig,
  EntityRegistry,
} from './entity-registry.types';

// Privacy-aware logger port.
export { NOOP_SYNC_LOGGER, toSyncLogError } from './sync-logger';
export type { SyncLogError, SyncLogMeta, SyncLogger } from './sync-logger';

// Entity key encoding helpers.
export { toEntityKey, parseEntityKey } from './entity-key.util';
