// The platform-agnostic storage contract.
//
// Both the web (Dexie/IndexedDB) and native (expo-sqlite) implementations
// satisfy this interface, so the rest of the app depends only on StorageRepo
// and never on a specific backend. The correct implementation is selected at
// build time via platform file extensions (see repoImpl.web.ts / repoImpl.native.ts).

import type { TranscriptDraft, TranscriptMeta, Transcript } from './schema';

export interface StorageRepo {
  /** All transcript metadatas, newest first (by createdAt desc). */
  list(): Promise<TranscriptMeta[]>;

  /** Full transcript by id, or undefined if it does not exist. */
  get(id: string): Promise<Transcript | undefined>;

  /** Validate the draft and persist a new transcript, returning the stored row. */
  create(draft: TranscriptDraft): Promise<Transcript>;

  /**
   * Patch a transcript's title and/or segments. Re-derives any denormalized
   * fields (searchText, segmentCount, updatedAt) and re-validates segments.
   * Rejects if the id does not exist.
   */
  update(
    id: string,
    patch: Partial<Pick<Transcript, 'title' | 'segments'>>,
  ): Promise<Transcript>;

  /** Delete by id. No-op if absent. */
  remove(id: string): Promise<void>;

  /**
   * Case-insensitive substring search over title + segment text.
   * Returns metadatas, newest first.
   */
  search(query: string): Promise<TranscriptMeta[]>;
}
