<?php

declare(strict_types=1);

namespace App\Framework\Exception\SecurityEvent;

use App\Framework\Exception\SecurityLogLevel;

/**
 * Account-Sperrung Event
 */
final readonly class AuthenticationAccountLockedEvent implements SecurityEventInterface
{
    public function __construct(
        public string $userId,
        public int $attempts
    ) {}

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

    public function getDescription(): string
    {
        return "User {$this->userId} account locked after {$this->attempts} failed attempts";
    }

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

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

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

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