package Server;

import Server.Cards.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;

class GameBoardTest {

    CardDeck deck = new CardDeck();
    Player player1 = new Player("A", TotemColor.PURPLE);
    Player player2 = new Player("B", TotemColor.YELLOW);
    Player player3 = new Player("C", TotemColor.BLUE);
    Player player4 = new Player("D", TotemColor.GREEN);
    Player player5 = new Player("E", TotemColor.RED);
    List<Player> players = new ArrayList<>();

    @BeforeEach
    void setUp() {
        players.add(player1);
        players.add(player2);
        players.add(player3);
        players.add(player4);
        players.add(player5);
        //deck.setForNPlayerPath(".\\src\\test\\resources\\files\\test_gameboard.csv",5);
        deck.setForNPlayer(getClass().getResourceAsStream("/files/test_gameboard.csv"), 5);

    }

    @Test
    void setTotemOnTile() {

        //tests that the tile is occupied

        GameBoard gameBoard = new GameBoard(Era.I,deck, players.size());
        Player player = new Player("Lucy", TotemColor.BLUE);
        OfferingTile tile = new OfferingTile(4);
        assertTrue(gameBoard.placeTotem(player,tile,gameBoard.getTurnTile() ));
    }

    @Test
    void drawBottomCard() {

        //test that a hunter card has been added to the player
        CardDeck deck2 = new CardDeck();
        //deck2.setForNPlayerPath("./src/test/resources/files/test_gameboard_characters.csv",5);
        deck2.setForNPlayer(getClass().getResourceAsStream("/files/test_gameboard_characters.csv"), 5);

        GameBoard gameBoard = new GameBoard(Era.I,deck2,players.size());
        Player player = new Player("Lucy", TotemColor.BLUE);
        gameBoard.setupInitialRows(5);
       // gameBoard.takeFromBottomRow(gameBoard.getBottomrow().get(2),player);
       // assertEquals(1,player.getPlayerTribe().countCharactersByType(CharacterType.HUNTER));
    }

    @Test
    void drawTopCard() {
        //tests that a hunter card has been added to the player
        CardDeck deck2 = new CardDeck();
        //deck2.setForNPlayerPath("./src/test/resources/files/test_gameboard_characters.csv",5);
        deck2.setForNPlayer(getClass().getResourceAsStream("/files/test_gameboard_characters.csv"), 5);

        GameBoard gameBoard = new GameBoard(Era.I,deck2,players.size());
        Player player = new Player("Lucy", TotemColor.BLUE);
        gameBoard.setupInitialRows(5);
        //gameBoard.DrawTopCard(gameBoard.getToprow().get(2),player);
        //assertEquals(1,player.getPlayerTribe().countCharactersByType(CharacterType.HUNTER));
    }

    @Test
    void eventsToSolve() {

        //tests that the result is a list of event cards
        CardDeck deck2 = new CardDeck();
       //deck2.setForNPlayerPath(".\\src\\test\\resources\\files\\test_gameboard_events.csv",5);
        deck2.setForNPlayer(getClass().getResourceAsStream("/files/test_gameboard_events.csv"), 5);

        GameBoard gameBoard = new GameBoard(Era.I,deck2,players.size());

        gameBoard.setupInitialRows(5);
        //assertTrue(gameBoard.EventsToSolve().getFirst().getCardId() > 84);

    }

    @Test
    void setRows() {
        //tests that the top row has n+4 cards
        GameBoard gameBoard = new GameBoard(Era.I,deck,players.size());
        //assertEquals(9,gameBoard.SetRows(5).size());
    }

    @Test
    void setOffersToNull() {

        //tests that the tiles are free

        GameBoard gameBoard = new GameBoard(Era.I,deck,players.size());

       // assertEquals(Collections.emptyList(),gameBoard.SetOffersToNull(5));

    }

    @Test
    void nextEra() {

        //tests that the eras progress

        GameBoard gameBoard = new GameBoard(Era.I,deck,players.size());
       // assertEquals(Era.II,gameBoard.NextEra());

    }

    @Test
    void changeBuildings() {

        //tests that with era change the top row of building is of era II
        CardDeck deck2 = new CardDeck();
        //deck2.setForNPlayerPath(".\\src\\test\\resources\\files\\only_building_deck.csv",5);
        deck2.setForNPlayer(getClass().getResourceAsStream("/files/only_building_deck.csv"), 5);

        GameBoard gameBoard = new GameBoard(Era.II,deck2,players.size());

        //assertEquals(Era.II,gameBoard.ChangeBuildings().getFirst().getEra());

    }

    @Test
    void getBuilding() {

        //tests that the building has gained the player as owner

        GameBoard gameBoard = new GameBoard(Era.I,deck,players.size());
        Player player = new Player("Diego",TotemColor.BLUE);
        player.addFood(4);
        //BuildingCard target = new BuildingCard(111,0,Era.II,4,3, Trigger.ENDGAME_BONUS_POINTS,null);
        //assertEquals(target.getOwner(),gameBoard.GetBuilding(player,target).getOwner());
    }


}