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

import it.polimi.ingsw.gc14.Model.Cards.Building.Effects.Building1;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.*;
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.*;
import static org.junit.jupiter.api.Assertions.assertThrows;

class SustenanceTest {

    @Test
    @DisplayName("Testing constructor")
    void testConstructor() {
        int era = 1;
        int prestigeDebt = 5;
        // Gli attributi di Sustenance era e EventType vengono testati in EventCardTest.

        Sustenance s = new Sustenance(era, prestigeDebt);
        assertEquals(prestigeDebt, s.getPrestigeDebt());
    }

    @Test
    @DisplayName("Exception Test Null List")
    void test_null() {
        ArrayList<Player> p = null;
        Sustenance s = new Sustenance(1,0);
        assertThrows(NullPointerException.class, () -> {
            s.activateEvent(p);
        });
    }

    @Test
    @DisplayName("No edge case")
    void activateEvent() {
        Player p1 = new Player("marco");
        Player p2 = new Player("giacomo");
        ArrayList<Player> players = new ArrayList<>(Arrays.asList(p1,p2));

        p1.addFood(4);
        new Inventor(1, 1).insert(p1);
        new Shaman(1, 5).insert(p1);
        new Builder(1, 5, 5).insert(p1);
        new Artist(1).insert(p1);
        new Hunter(1, true).insert(p1);
        new Gatherer(1).insert(p1);

        p2.addFood(1);
        new Artist(1).insert(p2);
        new Hunter(1, true).insert(p2);
        new Hunter(1, true).insert(p2);



        Sustenance s = new Sustenance(1,2);
        s.activateEvent(players);
        assertEquals(1, p1.getFoodValue());
        assertEquals(0, p2.getFoodValue());
        assertEquals(0, p1.getPrestigeValue());
        assertEquals(-4, p2.getPrestigeValue());
    }

    @Test
    @DisplayName("Building 1 testing")
    void activateEvent2() {
        Player p1 = new Player("marco");
        Player p2 = new Player("giacomo");
        ArrayList<Player> players = new ArrayList<>(Arrays.asList(p1,p2));

        p1.addFood(5);
        new Inventor(1, 1).insert(p1);
        new Shaman(1, 5).insert(p1);
        new Builder(1, 5, 5).insert(p1);
        new Artist(1).insert(p1);
        new Hunter(1, true).insert(p1);
        new Gatherer(1).insert(p1);

        p2.addFood(2);
        new Artist(1).insert(p2);
        new Artist(1).insert(p2);
        new Artist(1).insert(p2);


        Building1 bd1 = new Building1(1, 1, 1, CharacterType.SHAMAN);
        Building1 bd2 = new Building1(1, 1, 1, CharacterType.ARTIST);

        bd1.buy(p1);
        bd2.buy(p2);

        Sustenance s = new Sustenance(1,2);
        s.activateEvent(players);
        assertEquals(2, p1.getFoodValue());
        assertEquals(1, p2.getFoodValue());
        assertEquals(0, p1.getPrestigeValue());
        assertEquals(0, p2.getPrestigeValue());
    }

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


        Sustenance s1 = new Sustenance(era, prestigeDebt);
        Sustenance s2 = (Sustenance) s1.clone();

        assertEquals(era, s2.getEra());
        assertEquals(EventType.SUSTENANCE, s2.getType());
        assertEquals(prestigeDebt, s2.getPrestigeDebt());
    }

    @Test
    @DisplayName("ToString testing")
    void toStringTest() {
        Sustenance s1 = new Sustenance(1, 5);

        assertEquals("Era:1, SUSTENANCE", s1.toString());
    }
}





