<?php

declare(strict_types=1);

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

use App\Framework\QrCode\ErrorCorrectionLevel;
use App\Framework\QrCode\QrCodeVersion;
use App\Framework\QrCode\ReedSolomon\ReedSolomonEncoder;

echo "=== Capacity Comparison ===\n\n";

for ($version = 1; $version <= 5; $version++) {
    $qrVersion = new QrCodeVersion($version);

    echo "Version $version:\n";

    foreach ([ErrorCorrectionLevel::L, ErrorCorrectionLevel::M] as $errorLevel) {
        $qrCapacity = $qrVersion->getDataCapacity($errorLevel);
        $rsCapacity = ReedSolomonEncoder::getDataCapacity($version, $errorLevel->value);

        echo "  {$errorLevel->value}: QrCodeVersion={$qrCapacity} bits (" . ($qrCapacity / 8) . " bytes), ";
        echo "ReedSolomon={$rsCapacity} codewords\n";

        // Check if they match when converted
        if (($qrCapacity / 8) != $rsCapacity) {
            echo "    ❌ MISMATCH: " . ($qrCapacity / 8) . " bytes vs $rsCapacity codewords\n";
        } else {
            echo "    ✅ MATCH\n";
        }
    }
    echo "\n";
}
