<?php

declare(strict_types=1);

namespace App\Tests\Unit;

use App\Util\ParsedCommand;
use PHPUnit\Framework\TestCase;

final class ParsedCommandTest extends TestCase
{
    public function testParseSimpleCommand(): void
    {
        $cmd = ParsedCommand::parse('/help');
        self::assertNotNull($cmd);
        self::assertSame('help', $cmd->name);
        self::assertSame([], $cmd->args);
        self::assertSame('', $cmd->tail);
    }

    public function testParseCommandWithArgs(): void
    {
        $cmd = ParsedCommand::parse('/chat 123');
        self::assertNotNull($cmd);
        self::assertSame('chat', $cmd->name);
        self::assertSame(['123'], $cmd->args);
        self::assertSame('123', $cmd->tail);
        self::assertSame(123, $cmd->argInt(0));
    }

    public function testParseColonSyntaxExtractsParam(): void
    {
        $cmd = ParsedCommand::parse('/bot_patch:NewName');
        self::assertNotNull($cmd);
        self::assertSame('bot_patch', $cmd->name);
        self::assertSame(['NewName'], $cmd->args);
    }

    public function testParseReturnsNullForPlainText(): void
    {
        self::assertNull(ParsedCommand::parse('hello'));
        self::assertNull(ParsedCommand::parse(''));
        self::assertNull(ParsedCommand::parse('   '));
    }
}
