<?php

declare(strict_types=1);

namespace App\Framework\Exception\SecurityEvent;

use App\Framework\Exception\SecurityLogLevel;

/**
 * Login-Fehler Event
 */
final readonly class AuthenticationLoginFailedEvent implements SecurityEventInterface
{
    public function __construct(
        public string $userId,
        public string $reason = 'invalid_credentials'
    ) {
    }

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

    public function getDescription(): string
    {
        return "User {$this->userId} login failure";
    }

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

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

    public function requiresAlert(): bool
    {
        // Login-Fehler sind nicht kritisch genug für sofortige Alerts
        return false;
    }

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