<?php

declare(strict_types=1);

namespace App\Framework\QrCode\ValueObjects;

/**
 * QR Code Error Correction Level
 *
 * Determines how much damage a QR Code can sustain and still be readable
 *
 * Phase 1 (MVP): M level only (15% recovery)
 * Phase 2: All levels (L, M, Q, H)
 */
enum ErrorCorrectionLevel: string
{
    case L = 'L'; // Low:      ~7%  recovery - 🔮 Phase 2
    case M = 'M'; // Medium:   ~15% recovery - ✅ Phase 1
    case Q = 'Q'; // Quartile: ~25% recovery - 🔮 Phase 2
    case H = 'H'; // High:     ~30% recovery - 🔮 Phase 2

    /**
     * Get format bits for error correction level
     */
    public function getFormatBits(): string
    {
        return match ($this) {
            self::L => '01',
            self::M => '00',
            self::Q => '11',
            self::H => '10',
        };
    }

    /**
     * Get recovery percentage
     */
    public function getRecoveryPercentage(): int
    {
        return match ($this) {
            self::L => 7,
            self::M => 15,
            self::Q => 25,
            self::H => 30,
        };
    }

    /**
     * Check if this level is implemented in current phase
     */
    public function isImplemented(): bool
    {
        return match ($this) {
            self::M => true,  // ✅ Phase 1
            self::L => false, // 🔮 Phase 2
            self::Q => false, // 🔮 Phase 2
            self::H => false, // 🔮 Phase 2
        };
    }

    /**
     * Get default level for MVP
     */
    public static function default(): self
    {
        return self::M;
    }
}
