<?php

declare(strict_types=1);

namespace App\Framework\Queue\ValueObjects;

/**
 * Enum representing job priority levels
 */
enum JobPriority: int
{
    case LOW = 1;
    case NORMAL = 5;
    case HIGH = 10;
    case URGENT = 20;
    case CRITICAL = 50;

    public function getDisplayName(): string
    {
        return match ($this) {
            self::LOW => 'Low',
            self::NORMAL => 'Normal',
            self::HIGH => 'High',
            self::URGENT => 'Urgent',
            self::CRITICAL => 'Critical'
        };
    }

    public function getIcon(): string
    {
        return match ($this) {
            self::LOW => '🔵',
            self::NORMAL => '⚪',
            self::HIGH => '🟡',
            self::URGENT => '🟠',
            self::CRITICAL => '🔴'
        };
    }

    public function getColor(): string
    {
        return match ($this) {
            self::LOW => 'blue',
            self::NORMAL => 'gray',
            self::HIGH => 'yellow',
            self::URGENT => 'orange',
            self::CRITICAL => 'red'
        };
    }

    public function isHigherThan(self $other): bool
    {
        return $this->value > $other->value;
    }

    public function isLowerThan(self $other): bool
    {
        return $this->value < $other->value;
    }

    public function equals(self $other): bool
    {
        return $this->value === $other->value;
    }

    public static function fromString(string $priority): self
    {
        return match (strtolower($priority)) {
            'low' => self::LOW,
            'normal' => self::NORMAL,
            'high' => self::HIGH,
            'urgent' => self::URGENT,
            'critical' => self::CRITICAL,
            default => throw new \InvalidArgumentException("Invalid priority: {$priority}")
        };
    }

    public function getDescription(): string
    {
        return match ($this) {
            self::LOW => 'Low priority - process when system is idle',
            self::NORMAL => 'Normal priority - standard processing',
            self::HIGH => 'High priority - expedited processing',
            self::URGENT => 'Urgent priority - immediate attention required',
            self::CRITICAL => 'Critical priority - highest precedence'
        };
    }

    public function getMaxRetries(): int
    {
        return match ($this) {
            self::LOW => 2,
            self::NORMAL => 3,
            self::HIGH => 5,
            self::URGENT => 8,
            self::CRITICAL => 10
        };
    }

    public function getTimeoutSeconds(): int
    {
        return match ($this) {
            self::LOW => 300,    // 5 minutes
            self::NORMAL => 600, // 10 minutes
            self::HIGH => 900,   // 15 minutes
            self::URGENT => 1800, // 30 minutes
            self::CRITICAL => 3600 // 60 minutes
        };
    }
}
