// src/services/processingErrors.ts

/**
 * Base class for all flyer processing errors.
 * This allows for catching all processing-related errors with a single `catch` block.
 */
export class FlyerProcessingError extends Error {
  constructor(message: string) {
    super(message);
    this.name = this.constructor.name;
    Object.setPrototypeOf(this, new.target.prototype);
  }
}

/**
 * Error thrown when PDF to image conversion fails (e.g., pdftocairo produces no output).
 */
export class PdfConversionError extends FlyerProcessingError {
  public stderr?: string;
  constructor(message: string, stderr?: string) {
    super(message);
    this.stderr = stderr;
  }
}

/**
 * Error thrown when the data returned from the AI service fails Zod validation.
 */
export class AiDataValidationError extends FlyerProcessingError {
  constructor(message: string, public validationErrors: object, public rawData: unknown) {
    super(message);
  }
}

/**
 * Error thrown when all geocoding providers fail to find coordinates for an address.
 */
export class GeocodingFailedError extends FlyerProcessingError {
  constructor(message: string) {
    super(message);
  }
}