package com.ghost.technic.server.card;

import com.ghost.technic.server.Player;
import com.ghost.technic.server.card.effect.impl.AllusionsOfGrandeurAbility;
import com.ghost.technic.server.card.impl.ArchonIdentityCard;
import com.ghost.technic.server.card.playable.impl.ActionCard;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import com.ghost.technic.server.card.misc.House;
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.LinkedList;
import java.util.List;
import java.util.Set;

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

class AllusionsOfGrandeurTest {

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

    @BeforeEach
    void setUp() {
        gameState = new GameState(new EventBus());
        actionService = new GameActionService(gameState);

        alice = Player.builder().name("Alice").archonIdentityCard(ArchonIdentityCard.builder().houses(Set.of(House.BROBNAR, House.SHADOWS, House.UNTAMED)).build()).build();

        // Alice picks House Sanctum, if opponent does not pick Sanctum, Alice gains 3 amber
        alice = new Player(alice) {
            @Override
            public House chooseHouse(Set<House> house) {
                return House.SANCTUM;
            }
        };

        bob = Player.builder().name("Bob").archonIdentityCard(ArchonIdentityCard.builder().houses(Set.of(House.SANCTUM, House.LOGOS, House.MARS)).build()).deck(new LinkedList<>(List.of(CreatureCard.builder().name("Some Mars Creature").house(House.MARS).build()))).build();

        bob = new Player(bob) {
            @Override
            public House chooseHouse(Set<House> house) {
                return House.MARS;
            }
        };

        gameState.setPlayers(alice, bob);
        gameState.setActivePlayer(alice);
    }

    @Test
    void testGainAmberIfOpponentDoesNotChooseDeclaredHouse() {
        // Alice plays Allusions of Grandeur and picks BROBNAR
        ActionCard allusions = ActionCard.builder().name("Allusions of Grandeur").house(House.UNFATHOMABLE).abilities(List.of(new AllusionsOfGrandeurAbility())).build();

        actionService.playCard(allusions, alice);
        assertEquals(0, alice.getAmber());

        // Bob chooses a different house (LOGOS)
        gameState.setActivePlayer(bob);
        bob.setAmber(0);
        actionService.chooseActiveHouse(bob);

        assertEquals(3, alice.getAmber(), "Alice should gain 3 amber because Bob did not choose BROBNAR");
    }
}
