package com.ghost.technic.server.card;

import com.ghost.technic.server.card.effect.impl.MusthicMurmookAbility;
import com.ghost.technic.server.card.keyword.Keyword;
import com.ghost.technic.server.card.keyword.KeywordAbility;
import com.ghost.technic.server.counter.Counters;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import com.ghost.technic.server.Player;
import com.ghost.technic.server.board.Flank;
import com.ghost.technic.server.card.playable.usable.impl.CreatureCard;
import com.ghost.technic.server.game.GameActionService;
import com.ghost.technic.server.game.GameState;
import com.ghost.technic.server.game.event.EventBus;

import java.util.List;
import java.util.Set;

import static org.junit.jupiter.api.Assertions.assertEquals;

class MusthicMurmookTest {

    private GameActionService actionService;
    private GameState gameState;
    private Player alice;
    private Player bob;

    @BeforeEach
    void setup() {
        gameState = new GameState(new EventBus());
        actionService = new GameActionService(gameState);
        bob = Player.builder().name("Bob").build();
        gameState.setPlayers(alice, bob);
    }

    @Test
    void testMusthicMurmookAffectsKeyCostAndDeals4Damage() {
        CreatureCard briarGrubbling = CreatureCard.builder()
                .name("Briar Grubbling")
                .power(2)
                .armor(0)
                .traits(List.of("Insect", "Beast"))
                .counters(new Counters())
                .keywords(Set.of(new Keyword(KeywordAbility.HAZARDOUS, 5)))
                .build();

        CreatureCard musthicMurmook = CreatureCard.builder()
                .name("Musthic Murmook")
                .power(3)
                .armor(0)
                .abilities(List.of(new MusthicMurmookAbility()))
                .counters(new Counters())
                .build();

        alice = Player.builder().name("Alice").build();

        alice = new Player(alice) {
            @Override
            public CreatureCard chooseCreature(List<CreatureCard> options, String reason) {
                return briarGrubbling; // target own creature for test
            }
        };

        gameState.setOwner(briarGrubbling, alice);
        gameState.setOwner(musthicMurmook, alice);

        actionService.playCreature(alice, briarGrubbling, Flank.LEFT);
        actionService.playCreature(alice, musthicMurmook, Flank.RIGHT); // should trigger 4 dmg on ally

        assertEquals(4, briarGrubbling.getDamage(), "Briar Grubbling should have taken 4 damage from play effect");
        assertEquals(1, actionService.calculateKeyCostModifier(alice));
        assertEquals(1, actionService.calculateKeyCostModifier(bob));
    }
}
