export type ContentKind = "prose" | "heading" | "formula" | "table";

export interface ParsedBlock {
  id: string;
  text: string;
  kind: ContentKind;
  included: boolean;
  pageNumber?: number;
  confidence?: number;
  warning?: string;
}

export interface ParsedChapter {
  id: string;
  title: string;
  sourceHref: string;
  blocks: ParsedBlock[];
  pageStart?: number;
  pageEnd?: number;
}

export interface ParsedBook {
  format: "epub" | "pdf";
  title: string;
  author: string;
  chapters: ParsedChapter[];
  pageCount?: number;
  requiresOcr?: boolean;
}

export type ParserErrorCode =
  | "invalid_epub"
  | "invalid_pdf"
  | "drm_or_encrypted"
  | "unsafe_archive_path"
  | "no_readable_content";

export class BookParserError extends Error {
  readonly code: ParserErrorCode;

  constructor(code: ParserErrorCode, message: string) {
    super(message);
    this.name = "BookParserError";
    this.code = code;
  }
}
