<?php

declare(strict_types=1);

namespace App\Framework\Exception\SecurityEvent;

use App\Framework\Exception\SecurityLogLevel;

/**
 * Exzessive Nutzung Event
 */
final readonly class SystemExcessiveUseEvent implements SecurityEventInterface
{
    public function __construct(
        public string $identifier,
        public int $limit,
        public int $currentUsage
    ) {
    }

    public function getEventIdentifier(): string
    {
        return "excessive_use:{$this->identifier},{$this->limit}";
    }

    public function getDescription(): string
    {
        return "Excessive usage detected for {$this->identifier} exceeding limit {$this->limit}";
    }

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

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

    public function requiresAlert(): bool
    {
        // Rate-Limiting-Verletzungen sind immer alert-würdig
        return true;
    }

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