<?php

declare(strict_types=1);

namespace App\Framework\Waf;

/**
 * WAF action types for request handling decisions
 */
enum WafAction: string
{
    case ALLOW = 'allow';
    case BLOCK = 'block';
    case MONITOR = 'monitor';
    case CHALLENGE = 'challenge';

    /**
     * Get action description
     */
    public function getDescription(): string
    {
        return match ($this) {
            self::ALLOW => 'Allow request to proceed normally',
            self::BLOCK => 'Block request with error response',
            self::MONITOR => 'Allow request but log for analysis',
            self::CHALLENGE => 'Request additional verification (CAPTCHA, rate limit)'
        };
    }

    /**
     * Get default HTTP status code
     */
    public function getDefaultHttpStatus(): int
    {
        return match ($this) {
            self::ALLOW, self::MONITOR => 200,
            self::BLOCK => 403,
            self::CHALLENGE => 429
        };
    }

    /**
     * Check if action allows request continuation
     */
    public function allowsContinuation(): bool
    {
        return match ($this) {
            self::ALLOW, self::MONITOR => true,
            self::BLOCK, self::CHALLENGE => false
        };
    }

    /**
     * Check if action requires logging
     */
    public function requiresLogging(): bool
    {
        return match ($this) {
            self::ALLOW => false,
            self::BLOCK, self::MONITOR, self::CHALLENGE => true
        };
    }

    /**
     * Get logging priority level
     */
    public function getLogLevel(): string
    {
        return match ($this) {
            self::ALLOW => 'debug',
            self::MONITOR => 'info',
            self::CHALLENGE => 'warning',
            self::BLOCK => 'error'
        };
    }

    /**
     * Check if action should trigger alerts
     */
    public function shouldAlert(): bool
    {
        return match ($this) {
            self::ALLOW, self::MONITOR => false,
            self::CHALLENGE, self::BLOCK => true
        };
    }
}
