export class PdfPipelineError extends Error {
  readonly code: string;

  constructor(message: string, code: string, options?: { cause?: unknown }) {
    super(message, options);
    this.name = new.target.name;
    this.code = code;
  }
}

export class PdfEncryptedError extends PdfPipelineError {
  constructor(message = "El PDF esta protegido o encriptado y no permite extraccion de texto.", options?: { cause?: unknown }) {
    super(message, "PDF_ENCRYPTED", options);
  }
}

export class PdfUnreadableError extends PdfPipelineError {
  constructor(message = "No fue posible leer el PDF.", options?: { cause?: unknown }) {
    super(message, "PDF_UNREADABLE", options);
  }
}

export class OcrUnavailableError extends PdfPipelineError {
  constructor(message = "OCRmyPDF no esta instalado o no esta disponible en PATH.", options?: { cause?: unknown }) {
    super(message, "OCR_UNAVAILABLE", options);
  }
}

export class OcrFailedError extends PdfPipelineError {
  readonly stderr?: string;

  constructor(message = "La ejecucion de OCRmyPDF fallo.", options?: { cause?: unknown; stderr?: string }) {
    super(message, "OCR_FAILED", options);
    this.stderr = options?.stderr;
  }
}

export class PdfNoTextDetectedError extends PdfPipelineError {
  constructor(message = "No se detecto texto util en el PDF despues de OCR.", options?: { cause?: unknown }) {
    super(message, "PDF_NO_TEXT", options);
  }
}
