package Server.Cards;

import org.junit.jupiter.api.Test;

import java.util.List;
import Server.Era;

import static org.junit.jupiter.api.Assertions.*;
class CardDeckTest {

    //Load 2 cards from CSV to cardDeck
    @Test
    void loadOnlyCharacter(){
        CardDeck cardDeck = new CardDeck();
        cardDeck.setForNPlayer(getClass().getResourceAsStream("/files/cards.csv"), 4);
        assertEquals(2, cardDeck.getTribeDeck().size());
    }

    //First create a new CardDeck filled with a 14 cards then he recreates said deck
    // with a different set of cards to emulate a new game
    @Test
    void doubleLoad(){
        CardDeck cardDeck = new CardDeck();

        //cardDeck.setForNPlayer("./src/test/resources/files/only_building_deck.csv", 4);
        cardDeck.setForNPlayer(getClass().getResourceAsStream("/files/only_building_deck.csv"), 4);
        assertEquals(0, cardDeck.getTribeDeck().size());
        assertEquals(6, cardDeck.getBuildingDeck(Era.I).size());
        assertEquals(7, cardDeck.getBuildingDeck(Era.II).size());
        assertEquals(8, cardDeck.getBuildingDeck(Era.III).size());

        //cardDeck.setForNPlayer("./src/test/resources/files/only_event_deck.csv", 4);
        cardDeck.setForNPlayer(getClass().getResourceAsStream("/files/only_event_deck.csv"), 4);
        assertEquals(3, cardDeck.getTribeDeck().size());
        assertEquals(0, cardDeck.getBuildingDeck(Era.I).size());
        assertEquals(0, cardDeck.getBuildingDeck(Era.II).size());
        assertEquals(0, cardDeck.getBuildingDeck(Era.III).size());
    }

    //Draw 5 cards from TribeDeck and 3 from BuildingDeck, then check if they are correctly
    // removed from cardDeck
    @Test
    void draw() {

        int tribeDraw = 5;
        int buildingDraw = 3;
        int drawnCards = tribeDraw + buildingDraw;

        CardDeck cardDeck = new CardDeck();
        //cardDeck.setForNPlayer("./src/test/resources/files/test_deck.csv", 5);
        cardDeck.setForNPlayer(getClass().getResourceAsStream("/files/test_deck.csv"), 5);

        //int deckSize = cardDeck.getTribeDeck().size() +  cardDeck.getBuildingDeck().size();

        List<Card> cards = cardDeck.drawTribe(tribeDraw);
        assertEquals(tribeDraw, cards.size());
        //List<BuildingCard> buildingCards = cardDeck.drawBuilding(buildingDraw);
        //assertEquals(buildingDraw, buildingCards.size());

        //int newDeckSize = cardDeck.getTribeDeck().size() +  cardDeck.getBuildingDeck().size();
        //assertEquals(deckSize - drawnCards, newDeckSize);
    }

    //draw 5 cards from TribeDeck
    @Test
    void drawTribe() {
        CardDeck cardDeck = new CardDeck();
        //cardDeck.setForNPlayer("./src/test/resources/files/test_deck.csv", 5);
        cardDeck.setForNPlayer(getClass().getResourceAsStream("/files/test_deck.csv"), 5);
        List<Card> cards = cardDeck.drawTribe(5);
        assertEquals(5, cards.size());
    }

    //draw 3 cards from BuildingDeck
    @Test
    void drawBuilding() {
        CardDeck cardDeck = new CardDeck();
        //cardDeck.setForNPlayer("./src/test/resources/files/test_deck.csv", 5);
        cardDeck.setForNPlayer(getClass().getResourceAsStream("/files/test_deck.csv"), 5);

       // List<BuildingCard> buildingCards = cardDeck.drawBuilding(3);
       // assertEquals(3, buildingCards.size());
    }

    //Try to draw 5 cards from a deck of only 3, then he returns only the remaining
    //cards in the deck
    @Test
    void drawTooManyCards() {
        CardDeck cardDeck = new CardDeck();
        //cardDeck.setForNPlayer("./src/test/resources/files/only_character_deck.csv", 5);
        cardDeck.setForNPlayer(getClass().getResourceAsStream("/files/only_character_deck.csv"), 5);

        List<Card> cards = cardDeck.drawTribe(5);
        assertEquals(3, cards.size());
    }


    @Test
    void shuffledDeck() {
        CardDeck cardDeck = new CardDeck();
       // cardDeck.setForNPlayer("./src/test/resources/files/test_deck.csv", 5);
        cardDeck.setForNPlayer(getClass().getResourceAsStream("/files/test_deck.csv"), 5);

        assertEquals(Era.I, cardDeck.drawTribe(1).getFirst().getEra());
        assertEquals(Era.FINAL, cardDeck.drawTribe(100).getLast().getEra());

      //  assertEquals(Era.I, cardDeck.drawBuilding(1).getFirst().getEra());
      //  assertEquals(Era.III, cardDeck.drawBuilding(100).getLast().getEra());
    }
}