<?php

namespace App\Framework\Smartlinks\Actions;

use App\Framework\Smartlinks\TokenAction;

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

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

    public function get(TokenAction $action): ?SmartlinkAction
    {
        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]);
    }
}
