<?php
declare(strict_types=1);

namespace App\Core\Registries;

final class PermissionRegistry
{
    private static array $items = [];
    private static array $groups = [];

    public static function register(string $group, array $definitions): void
    {
        self::$groups[$group] = $definitions;
        foreach ($definitions as $key => $labels) {
            self::$items[$key] = array_merge($labels, ['group' => $group]);
        }
    }

    public static function get(string $key): ?array
    {
        return self::$items[$key] ?? null;
    }

    public static function getAll(): array
    {
        return self::$items;
    }

    public static function getByGroup(string $group): array
    {
        return self::$groups[$group] ?? [];
    }

    public static function getAllGrouped(): array
    {
        return self::$groups;
    }

    public static function has(string $key): bool
    {
        return isset(self::$items[$key]);
    }
}