<?php

namespace App\Enums;

enum AppointmentStatus: string
{
    case Pending = 'pending';
    case Confirmed = 'confirmed';
    case CheckedIn = 'checked_in';
    case Completed = 'completed';
    case Cancelled = 'cancelled';
    case NoShow = 'no_show';

    /** Statuses that occupy the slot (enforced by the unique slot key). */
    public static function active(): array
    {
        return [self::Pending, self::Confirmed, self::CheckedIn, self::Completed];
    }

    public function holdsSlot(): bool
    {
        return in_array($this, self::active(), true);
    }

    /** Allowed transitions; guards the status endpoint. */
    public function canTransitionTo(self $to): bool
    {
        return match ($this) {
            self::Pending => in_array($to, [self::Confirmed, self::CheckedIn, self::Cancelled, self::NoShow], true),
            self::Confirmed => in_array($to, [self::CheckedIn, self::Completed, self::Cancelled, self::NoShow], true),
            self::CheckedIn => in_array($to, [self::Completed, self::Cancelled], true),
            self::Completed, self::Cancelled, self::NoShow => false,
        };
    }

    public function label(): string
    {
        return __(match ($this) {
            self::Pending => 'Pending',
            self::Confirmed => 'Confirmed',
            self::CheckedIn => 'Checked in',
            self::Completed => 'Completed',
            self::Cancelled => 'Cancelled',
            self::NoShow => 'No-show',
        });
    }

    public function color(): string
    {
        return match ($this) {
            self::Pending => '#F5A524',
            self::Confirmed => '#0EA5E9',
            self::CheckedIn => '#8B5CF6',
            self::Completed => '#22C55E',
            self::Cancelled => '#94A3B8',
            self::NoShow => '#EF4444',
        };
    }
}
