<?php
require_once 'config/constants.php';
require_once 'services/MessageService.php';

echo "Testing PDF Custom Generation...\n";

$service = new MessageService(null);

$templateDir = __DIR__ . '/uploads/templates/';
$outputDir = __DIR__ . '/uploads/temp_pdfs/';

if (!file_exists($outputDir)) mkdir($outputDir, 0777, true);

// Pick the first jpeg file found in templates
$files = glob($templateDir . '*.jpeg');
if (empty($files)) $files = glob($templateDir . '*.jpg');

if (empty($files)) {
    die("No template file found in $templateDir.\n");
}

$templatePath = $files[0];
$outputPath = $outputDir . 'test_custom_' . time() . '.pdf';

$contactName = "CUSTOM BOLD NAME";
$options = [
    'pos_x' => 50,
    'pos_y' => 90,
    'font_size' => 40,
    'font_color' => '#FF0000' // Red color to verify
];

echo "Generating PDF with red bold text at bottom...\n";
$result = $service->generateBirthdayPdf($templatePath, $contactName, $outputPath, $options);

if ($result) {
    echo "PDF Generation Successful: $outputPath\n";
    echo "Please check the PDF manually to verify alignment and style.\n";
} else {
    echo "PDF Generation FAILED.\n";
}
?>
