package com.ghost.technic.server.card;

import com.ghost.technic.server.card.effect.impl.DirectorZYXAbility;
import com.ghost.technic.server.card.impl.ArchonIdentityCard;
import com.ghost.technic.server.game.GameTurnManager;
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.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.List;
import java.util.Set;

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

class DirectorZYXTest {

    GameActionService gameActionService;
    GameState gameState;
    Player player;
    CreatureCard topCreatureCard;
    CreatureCard secondCreatureCard;

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

        ArchonIdentityCard archonIdentityCard = ArchonIdentityCard.builder().houses(Set.of(House.SANCTUM, House.LOGOS, House.UNFATHOMABLE)).build();
        player = Player.builder().name("Z.Y.X. Player").archonIdentityCard(archonIdentityCard).build();
        topCreatureCard = CreatureCard.builder().name("Top card").build();
        secondCreatureCard = CreatureCard.builder().name("Second card").build();
        player.getDeck().addAll(List.of(topCreatureCard, secondCreatureCard));

        gameState.setPlayers(player, Player.builder().name("Opponent").build());
        gameState.setOwner(player.getDeck().getFirst(), player);

        CreatureCard director = CreatureCard.builder()
                .name("Director of Z.Y.X.")
                .house(House.LOGOS)
                .power(3)
                .abilities(List.of(new DirectorZYXAbility()))
                .build();

        gameState.setOwner(director, player);
        gameActionService.playCreature(player, director, Flank.LEFT);
    }

    @Test
    void testDirectorZYXArchivesTopCard() {
        int before = player.getArchives().size();

        GameTurnManager turnManager = new GameTurnManager(gameState, gameActionService);
        turnManager.handleStartOfTurnAbilities(player);

        assertEquals(before + 1, player.getArchives().size(), "Should archive one card at start of turn");
        assertEquals(topCreatureCard, player.getArchives().getFirst());
        assertEquals(secondCreatureCard, player.getDeck().getFirst());
    }
}
