<?php

declare(strict_types=1);

namespace App\Framework\LiveComponents\ValueObjects;

/**
 * Quarantine Status
 *
 * Status eines hochgeladenen Files in Quarantäne.
 * Durchläuft Lifecycle: pending -> scanning -> approved/rejected
 */
enum QuarantineStatus: string
{
    case PENDING = 'pending';       // Wartet auf Scan
    case SCANNING = 'scanning';     // Virus-Scan läuft
    case APPROVED = 'approved';     // Sicher, kann ausgeliefert werden
    case REJECTED = 'rejected';     // Gefährlich, muss gelöscht werden
    case EXPIRED = 'expired';       // Scan-Timeout überschritten

    public function isPending(): bool
    {
        return $this === self::PENDING;
    }

    public function isScanning(): bool
    {
        return $this === self::SCANNING;
    }

    public function isApproved(): bool
    {
        return $this === self::APPROVED;
    }

    public function isRejected(): bool
    {
        return $this === self::REJECTED;
    }

    public function isExpired(): bool
    {
        return $this === self::EXPIRED;
    }

    public function isFinal(): bool
    {
        return match ($this) {
            self::APPROVED, self::REJECTED, self::EXPIRED => true,
            default => false
        };
    }

    public function canTransitionTo(self $newStatus): bool
    {
        return match ($this) {
            self::PENDING => in_array($newStatus, [self::SCANNING, self::EXPIRED]),
            self::SCANNING => in_array($newStatus, [self::APPROVED, self::REJECTED, self::EXPIRED]),
            default => false // Final states cannot transition
        };
    }
}
