<?php

declare(strict_types=1);

namespace App\Framework\Exception\SecurityEvent;

use App\Framework\Exception\SecurityLogLevel;

/**
 * Zugriff verweigert Event
 */
final readonly class AuthorizationAccessDeniedEvent implements SecurityEventInterface
{
    public function __construct(
        public string $userId,
        public string $resource,
        public string $action = 'access'
    ) {
    }

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

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

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

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

    public function requiresAlert(): bool
    {
        return false;
    }

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