package it.polimi.ingsw.gc14.Model.Cards.TribeCards.Events;

import it.polimi.ingsw.gc14.Model.Cards.Building.EffectType;
import it.polimi.ingsw.gc14.Model.Cards.Building.Effects.Building0;
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.Hunter;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.EventCard;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.EventType;
import it.polimi.ingsw.gc14.Model.Player;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.Arrays;

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

class HuntTest {
    @Test
    @DisplayName("Testing constructor")
    void testConstructor() {
        // Gli attributi di Hunt era e EventType vengono testati in EventCardTest.

        // Gli attributi foodMultiplier e prestigeMultiplier non possono essere testati singolarmente in quanto non hanno metodi getter
        // Ne viene testato il corretto funzionamento indirettamente attraverso applyEffect.

        // Come conseguenza finale, non può essere testato il costruttore di Hunt
    }

    @Test
    @DisplayName("No edge case test")
    void activateEvent() {
        Player p1 = new Player("Giacomo");
        Player p2 = new Player("xiaomi");

        ArrayList<Player> players = new ArrayList<>(Arrays.asList(p1, p2));
        Hunt h1 = new Hunt(1, 3);

        new Hunter(1, true).insert(p1);
        new Hunter(1, false).insert(p1);
        new Hunter(1, false).insert(p2);

        h1.activateEvent(players);
        assertEquals(6, p1.getPrestigeValue());
        assertEquals(2, p1.getFoodValue());
        assertEquals(3, p2.getPrestigeValue());
        assertEquals(1, p2.getFoodValue());
    }

    @Test
    @DisplayName("no Hunters test")
    void activateEvent2() {
        Player p1 = new Player("Giacomo");
        Player p2 = new Player("xiaomi");

        ArrayList<Player> players = new ArrayList<>(Arrays.asList(p1, p2));
        Hunt h1 = new Hunt(1, 3);
        h1.activateEvent(players);

        assertEquals(0, p1.getPrestigeValue());
        assertEquals(0, p1.getFoodValue());
        assertEquals(0, p2.getPrestigeValue());
        assertEquals(0, p2.getFoodValue());
    }

    @Test
    @DisplayName("p2 has building 7")
    void activateEvent3() {
        Player p1 = new Player("Giacomo");
        Player p2 = new Player("xiaomi");
        Player p3 = new Player("test");

        ArrayList<Player> players = new ArrayList<>(Arrays.asList(p1, p2, p3));
        Hunt h1 = new Hunt(1, 3);

        new Hunter(1, true).insert(p1);
        new Hunter(1, false).insert(p1);
        new Hunter(1, false).insert(p2);

        BuildingCard bc = new BuildingCard(7, 1, 5, 5);
        p2.addFood(5);
        bc.buy(p2);

        new Hunter(1, false).insert(p3);


        h1.activateEvent(players);
        assertEquals(6, p1.getPrestigeValue());
        assertEquals(2, p1.getFoodValue());
        assertEquals(4, p2.getPrestigeValue());
        assertEquals(2, p2.getFoodValue());
        assertEquals(3, p3.getPrestigeValue());
        assertEquals(1, p3.getFoodValue());
    }

    @Test
    @DisplayName("clone testing")
    void cloneTest() {
        int era = 1;
        int prestigeMultiplier = 3;

        Hunt h1 = new Hunt(era, prestigeMultiplier);
        Hunt h2 = (Hunt) h1.clone();

        assertEquals(1, h2.foodMultiplier);
        assertEquals(3, h2.prestigeMultiplier);
        assertEquals(1, h2.getEra());
        assertEquals(EventType.HUNT, h2.getType());
    }

    @Test
    @DisplayName("ToString testing")
    void toStringTest() {
        Hunt h1 = new Hunt(1, 3);

        assertEquals("Era:1, HUNT", h1.toString());
    }
}