package thb.jeanluc.adventure.command;

import org.junit.jupiter.api.Test;
import thb.jeanluc.adventure.game.GameContext;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

class CommandRegistryTest {

    private static class StubCommand implements Command {
        @Override public void execute(GameContext ctx, List<String> args) {}
        @Override public String help() { return "stub"; }
    }

    @Test
    void register_andFindByEachAlias() {
        CommandRegistry r = new CommandRegistry();
        StubCommand cmd = new StubCommand();
        r.register(cmd, "go", "move", "walk");

        assertThat(r.find("go")).contains(cmd);
        assertThat(r.find("MOVE")).contains(cmd);
        assertThat(r.find("walk")).contains(cmd);
    }

    @Test
    void find_unknownVerb_returnsEmpty() {
        assertThat(new CommandRegistry().find("nope")).isEmpty();
    }

    @Test
    void distinctCommands_deduplicatesAliases() {
        CommandRegistry r = new CommandRegistry();
        StubCommand a = new StubCommand();
        StubCommand b = new StubCommand();
        r.register(a, "x", "y");
        r.register(b, "z");

        assertThat(r.distinctCommands()).containsExactlyInAnyOrder(a, b);
    }
}
