<?php

declare(strict_types=1);

require_once __DIR__ . '/../../vendor/autoload.php';

use App\Framework\QrCode\QrCodeGenerator;
use App\Framework\QrCode\ValueObjects\ErrorCorrectionLevel;
use App\Framework\QrCode\ValueObjects\QrCodeConfig;
use App\Framework\QrCode\ValueObjects\QrCodeVersion;
use App\Framework\QrCode\ValueObjects\EncodingMode;

echo "=== Checking Quiet Zone ===\n\n";

$config = new QrCodeConfig(
    version: QrCodeVersion::fromNumber(1),
    errorCorrectionLevel: ErrorCorrectionLevel::M,
    encodingMode: EncodingMode::BYTE
);

$matrix = QrCodeGenerator::generate("A", $config);
$size = $matrix->getSize();

echo "Matrix size: {$size}x{$size}\n\n";

// Test with different quiet zones
$quietZones = [4, 8, 10];

foreach ($quietZones as $qz) {
    $scale = 20;
    $totalSize = ($size + 2 * $qz) * $scale;
    
    $image = imagecreate($totalSize, $totalSize);
    $white = imagecolorallocate($image, 255, 255, 255);
    $black = imagecolorallocate($image, 0, 0, 0);
    
    imagefill($image, 0, 0, $white);
    
    for ($row = 0; $row < $size; $row++) {
        for ($col = 0; $col < $size; $col++) {
            if ($matrix->getModuleAt($row, $col)->isDark()) {
                $x = ($qz + $col) * $scale;
                $y = ($qz + $row) * $scale;
                
                for ($dy = 0; $dy < $scale; $dy++) {
                    for ($dx = 0; $dx < $scale; $dx++) {
                        imagesetpixel($image, $x + $dx, $y + $dy, $black);
                    }
                }
            }
        }
    }
    
    $filename = "qrcode-qz{$qz}.png";
    imagepng($image, "/var/www/html/public/{$filename}", 0);
    
    echo "✅ Generated: {$filename}\n";
    echo "   Quiet Zone: {$qz} modules\n";
    echo "   Total Size: {$totalSize}x{$totalSize}px\n";
    echo "   QR Code Size: " . ($size * $scale) . "x" . ($size * $scale) . "px\n";
    echo "   White Border: " . ($qz * $scale) . "px on each side\n\n";
}

echo "Standard requires 4 modules quiet zone minimum.\n";
echo "We're testing with 4, 8, and 10 modules.\n\n";

echo "URLs to test:\n";
echo "1. https://localhost/qrcode-qz4.png (standard)\n";
echo "2. https://localhost/qrcode-qz8.png (double)\n";
echo "3. https://localhost/qrcode-qz10.png (extra large)\n";

