<?php
declare(strict_types=1);

namespace App\Core\Registries;

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

    public static function register(string $name, callable $calculator): void
    {
        self::$items[$name] = ['calculator' => $calculator];
    }

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

    public static function calculate(string $name, array $context = []): mixed
    {
        if (!isset(self::$items[$name])) {
            throw new \RuntimeException("Calculator not found: {$name}");
        }
        return (self::$items[$name]['calculator'])($context);
    }

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

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