// src/types/pdf-poppler.d.ts

/**
 * This is a custom type declaration file for the 'pdf-poppler' module.
 * Since no official @types/pdf-poppler package exists, this file provides
 * TypeScript with the necessary type information to understand the module's
 * structure, preventing import errors and enabling type checking.
 */
declare module 'pdf-poppler' {
  /**
   * Defines the options available for the main `convert` method.
   * This appears to be a simplified wrapper around pdftocairo.
   */
  export interface ConvertOptions {
    /**
     * The output image format.
     */
    format?: 'jpeg' | 'png' | 'tiff';
    /**
     * The directory where output images will be saved.
     */
    out_dir?: string;
    /**
     * The prefix for the output image files.
     */
    out_prefix?: string;
    /**
     * Specify a page number to convert a specific page, or null to convert all pages.
     */
    page?: number | null;
    /**
     * Specifies the resolution, in DPI. The default is 72 DPI.
     */
    resolution?: number;
    /**
     * Scales each page to fit in scale-to x scale-to pixel square.
     */
    scale_to?: number;
  }

  /**
   * Defines the options available for the pdfToCairo conversion method.
   * These options correspond to the command-line arguments for the `pdftocairo` utility.
   */
  export interface PopplerOptions {
    antialias?: 'default' | 'gray' | 'none' | 'subpixel';
    cropBox?: boolean;
    cropHeight?: number;
    cropWidth?: number;
    cropSize?: number;
    cropX?: number;
    cropY?: number;
    duplex?: boolean;
    epsFile?: boolean;
    expand?: boolean;
    firstPage?: number;
    grayFile?: boolean;
    lastPage?: number;
    jpegFile?: boolean;
    jpegOptions?: string;
    level2?: boolean;
    level3?: boolean;
    monoFile?: boolean;
    noCenter?: boolean;
    noCrop?: boolean;
    noRotate?: boolean;
    noShrink?: boolean;
    ownerPassword?: string;
    paperHeight?: number;
    paperWidth?: number;
    paperSize?: 'letter' | 'legal' | 'A4' | 'A3' | 'match';
    pngFile?: boolean;
    psFile?: boolean;
    pdfFile?: boolean;
    resolution?: number;
    scaleTo?: number;
    scaleToX?: number;
    scaleToY?: number;
    svgFile?: boolean;
    tiffFile?: boolean;
    userPassword?: string;
  }

  /**
   * Defines the structure of the PDF information object returned by `pdfInfo`.
   */
  export interface PdfInfo {
    // Based on common pdfinfo output
    title: string;
    author: string;
    creator: string;
    producer: string;
    creationDate: string;
    modDate: string;
    tagged: boolean;
    form: string;
    pages: number;
    encrypted: boolean;
    pageSize: string;
    fileSize: string;
    optimized: boolean;
    pdfVersion: string;
  }

  export class Poppler {
    constructor(binPath?: string);
    pdfToCairo(file: string, outputFilePrefix?: string, options?: PopplerOptions): Promise<string>;
    pdfInfo(file: string, options?: { ownerPassword?: string; userPassword?: string }): Promise<PdfInfo>;
    pdfToPs(file: string, outputFile: string, options?: any): Promise<string>;
    pdfToText(file: string, outputFile: string, options?: any): Promise<string>;
  }

  /**
   * Converts a PDF file to images. This seems to be a convenience function provided by the library.
   * @param pdfPath The path to the PDF file.
   * @param options The conversion options.
   */
  export function convert(pdfPath: string, options?: ConvertOptions): Promise<string>;

  export default Poppler;
}
