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

import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.Artist;
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 CavePaintingsTest {

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

        // Gli attributi NLower, NPrestigeRem e NPrestigeMul 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 CavePainting
    }

    @Test
    @DisplayName("No edge case test")
    void activateEvent() {
        Player p1 = new Player("Marco");
        Player p2 = new Player("Giacomo");
        ArrayList<Player> players = new ArrayList<>(Arrays.asList(p1, p2));
        CavePaintings cp1 = new CavePaintings(1, 1, 3, 2);

        new Artist(1).insert(p2);
        cp1.activateEvent(players);

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

    @Test
    @DisplayName("Multiple activations test")
    void activateEvent1() {
        Player p1 = new Player("Marco");
        ArrayList<Player> players = new ArrayList<>(Arrays.asList(p1));
        CavePaintings cp1 = new CavePaintings(1, 1, 3, 2);
        CavePaintings cp2 = new CavePaintings(1, 1, 3, 4);
        CavePaintings cp3 = new CavePaintings(1, 1, 10, 2);

        cp1.activateEvent(players);
        assertEquals(-3, p1.getPrestigeValue());
        assertEquals(0, p1.getFoodValue());

        new Artist(1).insert(p1);
        new Artist(1).insert(p1);
        cp2.activateEvent(players);
        assertEquals(5, p1.getPrestigeValue());
        assertEquals(0, p1.getFoodValue());

        p1.artists.clear();
        cp3.activateEvent(players);
        assertEquals(-5, p1.getPrestigeValue());
        assertEquals(0, p1.getFoodValue());
    }

    @Test
    @DisplayName("Building 9 test")
    void activateEvent2() {
        Player p1 = new Player("Marco");
        ArrayList<Player> players = new ArrayList<>(Arrays.asList(p1));
        CavePaintings cp1 = new CavePaintings(1, 1, 3, 2);
        BuildingCard bc1 = new BuildingCard(9,1,5,5);
        p1.addFood(5);
        bc1.buy(p1);
        new Artist(1).insert(p1);
        cp1.activateEvent(players);

        assertEquals(2, p1.getPrestigeValue());
        assertEquals(1, p1.getFoodValue());


        BuildingCard bc2 = new BuildingCard(9,1,5,5);
        p1.addFood(5);
        bc2.buy(p1);
        new Artist(1).insert(p1);
        new Artist(1).insert(p1);
        cp1.activateEvent(players);

        assertEquals(8, p1.getPrestigeValue());
        assertEquals(7, p1.getFoodValue());
    }

    @Test
    @DisplayName("Clone testing")
    void cloneTest() {
        int era = 1;

        CavePaintings cv1 = new CavePaintings(era, 1,1,1);
        CavePaintings cv2 = (CavePaintings) cv1.clone();

        assertEquals(1, cv2.getEra());
        assertEquals(EventType.CAVE_PAINTINGS, cv2.getType());
    }

    @Test
    @DisplayName("ToString testing")
    void toStringTest() {
        CavePaintings cv1 = new CavePaintings(1, 1,1,1);

        assertEquals("Era:1, CAVE_PAINTINGS", cv1.toString());
    }
}