<?php

namespace App\Domain\Event\Enums;

enum EventStatus: string
{
    case Draft = 'draft';
    case Published = 'published';
    case RegistrationClosed = 'registration_closed';
    case InProgress = 'in_progress';
    case Completed = 'completed';
    case Cancelled = 'cancelled';

    public function label(): string
    {
        return match ($this) {
            self::Draft => 'مسودة',
            self::Published => 'منشور',
            self::RegistrationClosed => 'التسجيل مغلق',
            self::InProgress => 'جارٍ',
            self::Completed => 'مكتمل',
            self::Cancelled => 'ملغي',
        };
    }

    public function color(): string
    {
        return match ($this) {
            self::Draft => 'gray',
            self::Published => 'green',
            self::RegistrationClosed => 'yellow',
            self::InProgress => 'blue',
            self::Completed => 'purple',
            self::Cancelled => 'red',
        };
    }

    public function canTransitionTo(self $target): bool
    {
        return match ($this) {
            self::Draft => in_array($target, [self::Published, self::Cancelled]),
            self::Published => in_array($target, [self::RegistrationClosed, self::InProgress, self::Cancelled]),
            self::RegistrationClosed => in_array($target, [self::InProgress, self::Published, self::Cancelled]),
            self::InProgress => in_array($target, [self::Completed, self::Cancelled]),
            self::Completed, self::Cancelled => false,
        };
    }
}
