export interface StorageAdapter {
  readonly name: string;

  create<T extends Record<string, unknown>>(
    collection: string,
    data: T,
  ): Promise<T & { id: string }>;

  read<T extends Record<string, unknown>>(collection: string, id: string): Promise<T | null>;

  update(collection: string, id: string, data: Record<string, unknown>): Promise<boolean>;

  delete(collection: string, id: string): Promise<boolean>;

  find<T extends Record<string, unknown>>(
    collection: string,
    filter?: Record<string, unknown>,
    opts?: {
      limit?: number;
      offset?: number;
      orderBy?: string;
      order?: 'asc' | 'desc';
    },
  ): Promise<T[]>;

  findOne<T extends Record<string, unknown>>(
    collection: string,
    filter: Record<string, unknown>,
  ): Promise<T | null>;

  count(collection: string, filter?: Record<string, unknown>): Promise<number>;

  transaction<T>(fn: (tx: StorageAdapter) => Promise<T>): Promise<T>;

  migrate(): Promise<void>;

  close(): Promise<void>;
}

export type StorageConfig =
  | { type: 'postgres'; url: string; enableVector?: boolean }
  | { type: 'pglite'; dataDir?: string }
  | { type: 'files'; dataDir: string; format?: 'json' | 'md' };
