<?php

declare(strict_types=1);

namespace App\Domain\QrCode\ValueObject;

enum QrCodeMode: int
{
    case NUMERIC = 1;
    case ALPHANUMERIC = 2;
    case BYTE = 4;
    case KANJI = 8;

    public function getCharacterCountBits(QrCodeVersion $version): int
    {
        return match ($this) {
            self::NUMERIC => match (true) {
                $version->getValue() <= 9 => 10,
                $version->getValue() <= 26 => 12,
                default => 14,
            },
            self::ALPHANUMERIC => match (true) {
                $version->getValue() <= 9 => 9,
                $version->getValue() <= 26 => 11,
                default => 13,
            },
            self::BYTE => match (true) {
                $version->getValue() <= 9 => 8,
                $version->getValue() <= 26 => 16,
                default => 16,
            },
            self::KANJI => match (true) {
                $version->getValue() <= 9 => 8,
                $version->getValue() <= 26 => 10,
                default => 12,
            },
        };
    }
}
