<?php

namespace Openguru\OpenCartFramework\Telegram;

use Openguru\OpenCartFramework\Telegram\Exceptions\TelegramCommandNotFoundException;

class TelegramCommandsRegistry
{
    private array $commands = [];

    public function addCommand(string $command, string $handler, ?string $description = null): void
    {
        $this->commands[$command] = [
            'handler' => $handler,
            'description' => $description,
        ];
    }

    public function resolve(string $command): string
    {
        if (! array_key_exists($command, $this->commands)) {
            throw new TelegramCommandNotFoundException($command);
        }

        return $this->commands[$command]['handler'];
    }
}
