<?php

declare(strict_types=1);

namespace App\Framework\Exception\SecurityEvent;

use App\Framework\Exception\SecurityLogLevel;

/**
 * XSS-Versuch Event
 */
final readonly class InputXssAttemptEvent implements SecurityEventInterface
{
    public function __construct(
        public string $field,
        public string $detectedPattern = 'generic_xss_pattern'
    ) {}

    public function getEventIdentifier(): string
    {
        return "input_xss_attempt:{$this->field}";
    }

    public function getDescription(): string
    {
        return "XSS attack attempt detected in field {$this->field}";
    }

    public function getLogLevel(): SecurityLogLevel
    {
        return SecurityLogLevel::WARN;
    }

    public function getCategory(): string
    {
        return 'input_validation';
    }

    public function requiresAlert(): bool
    {
        return true;
    }

    public function toArray(): array
    {
        return [
            'field' => $this->field,
            'detectedPattern' => $this->detectedPattern,
            'event_identifier' => $this->getEventIdentifier(),
            'category' => $this->getCategory(),
            'log_level' => $this->getLogLevel()->value,
            'requires_alert' => $this->requiresAlert()
        ];
    }
}
