<?php

declare(strict_types=1);

namespace App\Framework\QrCode\ValueObjects;

use App\Framework\Svg\ValueObjects\Styling\SvgColor;

/**
 * QR Code Styling Configuration
 *
 * Styling options for rendering QR Codes
 * Phase 1: Basic colors
 * Phase 2: Gradients, rounded corners
 * Phase 3: Logo overlay, custom shapes
 */
final readonly class QrCodeStyle
{
    public readonly SvgColor $darkColor;
    public readonly SvgColor $lightColor;

    public function __construct(
        public int $moduleSize = 10,              // Size of each module in pixels
        ?SvgColor $darkColor = null,              // Color for dark modules
        ?SvgColor $lightColor = null,             // Color for light modules
        public int $quietZoneSize = 4,            // Quiet zone in modules
        public bool $includeQuietZone = true      // Whether to include quiet zone in output
    ) {
        // Use default colors if not provided
        $this->darkColor = $darkColor ?? SvgColor::black();
        $this->lightColor = $lightColor ?? SvgColor::white();
    }

    /**
     * Create default style (black on white, 10px modules)
     */
    public static function default(): self
    {
        return new self(
            moduleSize: 10,
            darkColor: SvgColor::black(),
            lightColor: SvgColor::white(),
            quietZoneSize: 4,
            includeQuietZone: true
        );
    }

    /**
     * Create compact style (smaller modules, no quiet zone)
     */
    public static function compact(): self
    {
        return new self(
            moduleSize: 5,
            darkColor: SvgColor::black(),
            lightColor: SvgColor::white(),
            quietZoneSize: 0,
            includeQuietZone: false
        );
    }

    /**
     * Create large style (bigger modules for printing)
     */
    public static function large(): self
    {
        return new self(
            moduleSize: 20,
            darkColor: SvgColor::black(),
            lightColor: SvgColor::white(),
            quietZoneSize: 4,
            includeQuietZone: true
        );
    }

    /**
     * Create inverted style (white on black)
     */
    public static function inverted(): self
    {
        return new self(
            moduleSize: 10,
            darkColor: SvgColor::white(),
            lightColor: SvgColor::black(),
            quietZoneSize: 4,
            includeQuietZone: true
        );
    }

    /**
     * With custom colors
     */
    public static function withColors(SvgColor $dark, SvgColor $light): self
    {
        return new self(
            moduleSize: 10,
            darkColor: $dark,
            lightColor: $light,
            quietZoneSize: 4,
            includeQuietZone: true
        );
    }

    /**
     * Calculate total canvas size
     */
    public function calculateCanvasSize(int $matrixSize): int
    {
        $modules = $matrixSize;

        if ($this->includeQuietZone) {
            $modules += ($this->quietZoneSize * 2);
        }

        return $modules * $this->moduleSize;
    }

    /**
     * Get quiet zone offset in pixels
     */
    public function getQuietZoneOffset(): int
    {
        return $this->includeQuietZone
            ? $this->quietZoneSize * $this->moduleSize
            : 0;
    }
}
