<?php

declare(strict_types=1);

namespace App\Framework\Waf;

/**
 * Status of a WAF layer analysis result
 */
enum LayerStatus: string
{
    case CLEAN = 'clean';
    case THREAT_DETECTED = 'threat_detected';
    case NEUTRAL = 'neutral';
    case ERROR = 'error';
    case SKIPPED = 'skipped';
    case TIMEOUT = 'timeout';

    /**
     * Check if status indicates a successful analysis
     */
    public function isSuccessful(): bool
    {
        return match ($this) {
            self::CLEAN,
            self::THREAT_DETECTED,
            self::NEUTRAL => true,
            default => false
        };
    }

    /**
     * Check if status indicates an error condition
     */
    public function isError(): bool
    {
        return match ($this) {
            self::ERROR,
            self::TIMEOUT => true,
            default => false
        };
    }

    /**
     * Check if status indicates a threat was found
     */
    public function isThreat(): bool
    {
        return $this === self::THREAT_DETECTED;
    }

    /**
     * Check if status indicates clean request
     */
    public function isClean(): bool
    {
        return $this === self::CLEAN;
    }

    /**
     * Get human-readable description
     */
    public function getDescription(): string
    {
        return match ($this) {
            self::CLEAN => 'Request passed all security checks',
            self::THREAT_DETECTED => 'Security threat detected',
            self::NEUTRAL => 'Unable to determine threat level',
            self::ERROR => 'Layer analysis failed',
            self::SKIPPED => 'Layer analysis was skipped',
            self::TIMEOUT => 'Layer analysis timed out'
        };
    }

    /**
     * Get severity level for logging/alerting
     */
    public function getSeverityLevel(): int
    {
        return match ($this) {
            self::CLEAN => 1,      // Info
            self::NEUTRAL => 2,     // Notice
            self::SKIPPED => 3,     // Warning
            self::TIMEOUT => 4,     // Error
            self::ERROR => 5,       // Critical
            self::THREAT_DETECTED => 6  // Alert
        };
    }
}
