<?php

declare(strict_types=1);

namespace App\Framework\QrCode\ValueObjects;

/**
 * Single QR Code Module (Pixel)
 *
 * Represents a single module in the QR Code matrix
 * Each module is either dark (1) or light (0)
 */
final readonly class Module
{
    private function __construct(
        private bool $isDark
    ) {}

    /**
     * Create dark module
     */
    public static function dark(): self
    {
        return new self(true);
    }

    /**
     * Create light module
     */
    public static function light(): self
    {
        return new self(false);
    }

    /**
     * Create from boolean
     */
    public static function fromBool(bool $isDark): self
    {
        return new self($isDark);
    }

    /**
     * Create from bit (0 or 1)
     */
    public static function fromBit(int $bit): self
    {
        return new self($bit === 1);
    }

    /**
     * Check if module is dark
     */
    public function isDark(): bool
    {
        return $this->isDark;
    }

    /**
     * Check if module is light
     */
    public function isLight(): bool
    {
        return !$this->isDark;
    }

    /**
     * Get as bit (0 or 1)
     */
    public function toBit(): int
    {
        return $this->isDark ? 1 : 0;
    }

    /**
     * Invert module (for masking)
     */
    public function invert(): self
    {
        return new self(!$this->isDark);
    }

    /**
     * Convert to string for debugging
     */
    public function toString(): string
    {
        return $this->isDark ? '█' : '░';
    }
}
