<?php

declare(strict_types=1);

namespace PpPhp\Core\Maintenance\Registry;

use PpPhp\Core\Maintenance\Contracts\MaintenanceRuleInterface;

final class RuleRegistry
{
    /**
     * @var array<string, MaintenanceRuleInterface>
     */
    private array $rules = [];

    public function register(MaintenanceRuleInterface $rule): void
    {
        $this->rules[$rule->id()] = $rule;
    }

    public function has(string $id): bool
    {
        return isset($this->rules[$id]);
    }

    public function get(string $id): ?MaintenanceRuleInterface
    {
        return $this->rules[$id] ?? null;
    }

    /**
     * @return MaintenanceRuleInterface[]
     */
    public function all(): array
    {
        return array_values($this->rules);
    }
}
