import {
  BaseFileSystem,
  TypedEventEmitter,
  FileSystemEventPayloads,
  IFileSystemCapabilities,
  FileEntry,
  FileMetadata,
  FSEvent,
  Disposable,
  FileStat,
} from "@firesystem/core";

interface IndexedDBConfig {
  dbName: string;
  version?: number;
  storeName?: string;
  enableExternalSync?: boolean;
  deepChangeDetection?: boolean;
}

declare class IndexedDBFileSystem extends BaseFileSystem {
  private db;
  private config;
  private watchers;
  private isInitialized;
  readonly events: TypedEventEmitter<FileSystemEventPayloads>;
  private broadcastChannel;
  private fileSnapshots;
  private pollingInterval;
  private enableExternalSync;
  private deepChangeDetection;
  readonly capabilities: IFileSystemCapabilities;
  constructor(config: IndexedDBConfig);
  private ensureDB;
  initialize(): Promise<void>;
  private loadAllFiles;
  readFile(path: string): Promise<FileEntry>;
  writeFile(
    path: string,
    content: any,
    metadata?: FileMetadata,
  ): Promise<FileEntry>;
  deleteFile(path: string): Promise<void>;
  exists(path: string): Promise<boolean>;
  readDir(path: string): Promise<FileEntry[]>;
  mkdir(path: string, recursive?: boolean): Promise<FileEntry>;
  rmdir(path: string, recursive?: boolean): Promise<void>;
  rename(oldPath: string, newPath: string): Promise<FileEntry>;
  move(sourcePaths: string[], targetPath: string): Promise<void>;
  copy(sourcePath: string, targetPath: string): Promise<FileEntry>;
  watch(pattern: string, callback: (event: FSEvent) => void): Disposable;
  stat(path: string): Promise<FileStat>;
  glob(pattern: string): Promise<string[]>;
  clear(): Promise<void>;
  size(): Promise<number>;
  private calculateHash;
  private calculateSize;
  private ensureParentExists;
  private deleteRecursive;
  private matchesPattern;
  private notifyWatchers;
  private generateWatcherId;
  private ensureRootExists;
  private setupBroadcastChannel;
  private broadcastChange;
  startWatching(pollingIntervalMs?: number): Promise<void>;
  stopWatching(): Promise<void>;
  private updateFileSnapshots;
  private checkForExternalChanges;
  private performDeepContentCheck;
  dispose(): void;
  canModify(path: string): Promise<boolean>;
  canCreateIn(parentPath: string): Promise<boolean>;
}

export { type IndexedDBConfig, IndexedDBFileSystem };
