<?php

declare(strict_types=1);

namespace App\Domain\QrCode\ValueObject;

enum MaskPattern: int
{
    case PATTERN_0 = 0; // (row + column) mod 2 == 0
    case PATTERN_1 = 1; // row mod 2 == 0
    case PATTERN_2 = 2; // column mod 3 == 0
    case PATTERN_3 = 3; // (row + column) mod 3 == 0
    case PATTERN_4 = 4; // (floor(row/2) + floor(column/3)) mod 2 == 0
    case PATTERN_5 = 5; // ((row * column) mod 2) + ((row * column) mod 3) == 0
    case PATTERN_6 = 6; // (((row * column) mod 2) + ((row * column) mod 3)) mod 2 == 0
    case PATTERN_7 = 7; // (((row + column) mod 2) + ((row * column) mod 3)) mod 2 == 0

    public function shouldMask(int $row, int $col): bool
    {
        return match ($this) {
            self::PATTERN_0 => ($row + $col) % 2 === 0,
            self::PATTERN_1 => $row % 2 === 0,
            self::PATTERN_2 => $col % 3 === 0,
            self::PATTERN_3 => ($row + $col) % 3 === 0,
            self::PATTERN_4 => (intval($row / 2) + intval($col / 3)) % 2 === 0,
            self::PATTERN_5 => ($row * $col) % 2 + ($row * $col) % 3 === 0,
            self::PATTERN_6 => (($row * $col) % 2 + ($row * $col) % 3) % 2 === 0,
            self::PATTERN_7 => (($row + $col) % 2 + ($row * $col) % 3) % 2 === 0,
        };
    }
}
