<?php
declare(strict_types=1);
namespace App\Platform\Soc\Event;

final class EventRegistry
{
    /** @var array<string,array{category:string,module:string,severity:EventSeverity}> */
    private array $definitions = [];

    public function __construct()
    {
        $this->registerDefaults();
    }

    public function register(string $name, string $category, string $module, EventSeverity $severity): void
    {
        $this->definitions[$name] = compact('category', 'module', 'severity');
    }

    /** @return array{category:string,module:string,severity:EventSeverity}|null */
    public function definition(string $name): ?array
    {
        return $this->definitions[$name] ?? null;
    }

    private function registerDefaults(): void
    {
        $this->register('auth.login.success', 'authentication', 'auth', EventSeverity::INFO);
        $this->register('auth.login.failed', 'authentication', 'auth', EventSeverity::WARNING);
        $this->register('auth.logout', 'authentication', 'auth', EventSeverity::INFO);
        $this->register('access.denied', 'authorization', 'security', EventSeverity::WARNING);
        $this->register('database.error', 'database', 'core', EventSeverity::CRITICAL);
        $this->register('runtime.exception', 'runtime', 'core', EventSeverity::CRITICAL);
        $this->register('update.installed', 'deployment', 'update_center', EventSeverity::INFO);
        $this->register('update.failed', 'deployment', 'update_center', EventSeverity::CRITICAL);
        $this->register('backup.completed', 'continuity', 'backup', EventSeverity::INFO);
        $this->register('backup.failed', 'continuity', 'backup', EventSeverity::CRITICAL);
        $this->register('health.scan.completed', 'health', 'health_monitor', EventSeverity::INFO);
        $this->register('permission.changed', 'authorization', 'permissions', EventSeverity::WARNING);
    }
}
