<?php

declare(strict_types=1);

namespace App\Framework\MagicLinks\Actions;

use App\Framework\MagicLinks\TokenAction;

final class DefaultActionRegistry implements ActionRegistry
{
    /** @var MagicLinkAction[] */
    private array $actions = [];

    public function register(MagicLinkAction $action): void
    {
        $this->actions[$action->getName()] = $action;
    }

    public function get(TokenAction $action): ?MagicLinkAction
    {
        return $this->actions[$action->name] ?? null;
    }

    public function has(TokenAction $action): bool
    {
        return isset($this->actions[$action->name]);
    }

    public function getAll(): array
    {
        return $this->actions;
    }

    public function unregister(TokenAction $action): void
    {
        unset($this->actions[$action->name]);
    }
}
