<?php

declare(strict_types=1);

namespace App\Framework\Exception\SecurityEvent;

use App\Framework\Exception\SecurityLogLevel;

/**
 * Bot Detection Event (Honeypot, Rate Limiting, etc.)
 */
final readonly class BotDetectedEvent implements SecurityEventInterface
{
    public function __construct(
        public string $reason,
        public string $ip,
        public string $userAgent,
        public ?string $detectionMethod = 'honeypot'
    ) {
    }

    public function getEventIdentifier(): string
    {
        return "bot_detected:{$this->detectionMethod}:{$this->ip}";
    }

    public function getDescription(): string
    {
        return "Bot activity detected: {$this->reason}";
    }

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

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

    public function requiresAlert(): bool
    {
        // Honeypot triggers sollten geloggt werden, aber nicht sofort alertieren
        // (außer bei ungewöhnlich vielen Versuchen von der gleichen IP)
        return false;
    }

    public function toArray(): array
    {
        return [
            'reason' => $this->reason,
            'ip' => $this->ip,
            'user_agent' => $this->userAgent,
            'detection_method' => $this->detectionMethod,
            'event_identifier' => $this->getEventIdentifier(),
            'category' => $this->getCategory(),
            'log_level' => $this->getLogLevel()->value,
            'requires_alert' => $this->requiresAlert(),
        ];
    }
}
