<?php

declare(strict_types=1);

namespace App\Framework\Svg\ValueObjects\Styling;

use App\Domain\Common\ValueObject\RGBColor;

/**
 * Enum for SVG named colors with RGB values
 * @see https://www.w3.org/TR/SVG11/types.html#ColorKeywords
 */
enum NamedColor: string
{
    case BLACK = 'black';
    case WHITE = 'white';
    case RED = 'red';
    case GREEN = 'green';
    case BLUE = 'blue';
    case YELLOW = 'yellow';
    case CYAN = 'cyan';
    case MAGENTA = 'magenta';
    case GRAY = 'gray';
    case GREY = 'grey';
    case SILVER = 'silver';
    case MAROON = 'maroon';
    case PURPLE = 'purple';
    case FUCHSIA = 'fuchsia';
    case LIME = 'lime';
    case OLIVE = 'olive';
    case NAVY = 'navy';
    case TEAL = 'teal';
    case AQUA = 'aqua';
    case ORANGE = 'orange';
    case TRANSPARENT = 'transparent';

    /**
     * Get RGB representation of named color
     */
    public function toRgb(): RGBColor
    {
        return match ($this) {
            self::BLACK => RGBColor::fromRgb(0, 0, 0),
            self::WHITE => RGBColor::fromRgb(255, 255, 255),
            self::RED => RGBColor::fromRgb(255, 0, 0),
            self::GREEN => RGBColor::fromRgb(0, 128, 0),
            self::BLUE => RGBColor::fromRgb(0, 0, 255),
            self::YELLOW => RGBColor::fromRgb(255, 255, 0),
            self::CYAN => RGBColor::fromRgb(0, 255, 255),
            self::MAGENTA => RGBColor::fromRgb(255, 0, 255),
            self::GRAY, self::GREY => RGBColor::fromRgb(128, 128, 128),
            self::SILVER => RGBColor::fromRgb(192, 192, 192),
            self::MAROON => RGBColor::fromRgb(128, 0, 0),
            self::PURPLE => RGBColor::fromRgb(128, 0, 128),
            self::FUCHSIA => RGBColor::fromRgb(255, 0, 255),
            self::LIME => RGBColor::fromRgb(0, 255, 0),
            self::OLIVE => RGBColor::fromRgb(128, 128, 0),
            self::NAVY => RGBColor::fromRgb(0, 0, 128),
            self::TEAL => RGBColor::fromRgb(0, 128, 128),
            self::AQUA => RGBColor::fromRgb(0, 255, 255),
            self::ORANGE => RGBColor::fromRgb(255, 165, 0),
            self::TRANSPARENT => RGBColor::fromRgb(0, 0, 0), // Transparent is handled via opacity
        };
    }

    /**
     * Check if color is transparent
     */
    public function isTransparent(): bool
    {
        return $this === self::TRANSPARENT;
    }

    /**
     * Get SVG color name
     */
    public function toSvgValue(): string
    {
        return $this->value;
    }

    /**
     * Get hex representation
     */
    public function toHex(): string
    {
        return $this->toRgb()->toHex();
    }
}
