<?php

declare(strict_types=1);

namespace App\Framework\Exception\SecurityEvent;

use App\Framework\Exception\SecurityLogLevel;

/**
 * SQL-Injection-Versuch Event
 */
final readonly class InputSqlInjectionAttemptEvent implements SecurityEventInterface
{
    public function __construct(
        public string $field,
        public string $detectedPattern = 'generic_sql_pattern'
    ) {
    }

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

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

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

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

    public function requiresAlert(): bool
    {
        // SQL-Injection-Versuche sind immer kritisch
        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(),
        ];
    }
}
