import { PDFDocument } from 'pdf-lib';
// 6x9 inches in Points (72 points/inch): 432 x 648 pt
// 6x9 inches in Millimeters: 152.4 x 228.6 mm
const EXPECTED_WIDTH_PT = 432;
const EXPECTED_HEIGHT_PT = 648;
const TOLERANCE_PT = 5; // Allow ~1.7mm tolerance for renderer rounding
export async function verify6x9PdfBuffer(pdfBuffer) {
    const errors = [];
    try {
        const pdfDoc = await PDFDocument.load(pdfBuffer);
        const pages = pdfDoc.getPages();
        const pageCount = pages.length;
        if (pageCount === 0) {
            errors.push('PDF contains 0 pages');
            return {
                isValid: false,
                pageCount: 0,
                widthPoints: 0,
                heightPoints: 0,
                widthMm: 0,
                heightMm: 0,
                errors,
            };
        }
        const firstPage = pages[0];
        const { width: widthPoints, height: heightPoints } = firstPage.getSize();
        const widthMm = (widthPoints / 72) * 25.4;
        const heightMm = (heightPoints / 72) * 25.4;
        // Check dimensions against 6x9 inches (432pt x 648pt)
        if (Math.abs(widthPoints - EXPECTED_WIDTH_PT) > TOLERANCE_PT) {
            errors.push(`Invalid page width: ${widthMm.toFixed(1)}mm (${widthPoints.toFixed(1)}pt). Expected 152.4mm (432pt) for 6×9 trim.`);
        }
        if (Math.abs(heightPoints - EXPECTED_HEIGHT_PT) > TOLERANCE_PT) {
            errors.push(`Invalid page height: ${heightMm.toFixed(1)}mm (${heightPoints.toFixed(1)}pt). Expected 228.6mm (648pt) for 6×9 trim.`);
        }
        return {
            isValid: errors.length === 0,
            pageCount,
            widthPoints,
            heightPoints,
            widthMm,
            heightMm,
            errors,
        };
    }
    catch (err) {
        return {
            isValid: false,
            pageCount: 0,
            widthPoints: 0,
            heightPoints: 0,
            widthMm: 0,
            heightMm: 0,
            errors: [`Failed to parse PDF document: ${err?.message || String(err)}`],
        };
    }
}
//# sourceMappingURL=verifier.js.map