package thb.jeanluc.adventure.command.impl;

import org.junit.jupiter.api.Test;

import java.util.List;

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

class TalkGiveCommandTest {

    @Test
    void talk_existingNpc_writesGreeting() {
        CommandTestSupport.World w = new CommandTestSupport.World();
        new TalkCommand().execute(w.ctx, List.of("old_man"));
        assertThat(w.io.lastOutput()).contains("Old Man").contains("greetings");
    }

    @Test
    void talk_missingNpc_complains() {
        CommandTestSupport.World w = new CommandTestSupport.World();
        new TalkCommand().execute(w.ctx, List.of("ghost"));
        assertThat(w.io.allOutput()).contains("no 'ghost'");
    }

    @Test
    void give_matchingReaction_swapsItems() {
        CommandTestSupport.World w = new CommandTestSupport.World();
        new TakeCommand().execute(w.ctx, List.of("lamp"));

        new GiveCommand().execute(w.ctx, List.of("lamp", "old_man"));

        assertThat(w.player.hasItem("lamp")).isFalse();
        assertThat(w.player.hasItem("key")).isTrue();
        assertThat(w.io.lastOutput()).contains("Take the key");
    }

    @Test
    void give_noReaction_complains() {
        CommandTestSupport.World w = new CommandTestSupport.World();
        new TakeCommand().execute(w.ctx, List.of("letter"));

        new GiveCommand().execute(w.ctx, List.of("letter", "old_man"));

        assertThat(w.player.hasItem("letter")).isTrue();
        assertThat(w.io.lastOutput()).contains("does not react");
    }

    @Test
    void give_unknownNpc_complains() {
        CommandTestSupport.World w = new CommandTestSupport.World();
        new TakeCommand().execute(w.ctx, List.of("lamp"));

        new GiveCommand().execute(w.ctx, List.of("lamp", "ghost"));

        assertThat(w.io.allOutput()).contains("no 'ghost'");
    }

    @Test
    void give_itemNotHeld_complains() {
        CommandTestSupport.World w = new CommandTestSupport.World();
        new GiveCommand().execute(w.ctx, List.of("lamp", "old_man"));
        assertThat(w.io.allOutput()).contains("not carrying");
    }
}
