package it.polimi.ingsw.gc14.Model.Cards.Building.Effects;

import it.polimi.ingsw.gc14.Model.Cards.Building.EffectType;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.Inventor;
import it.polimi.ingsw.gc14.Model.Player;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

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

class Building4Test {

    @Test
    @DisplayName("Testing constructor")
    void testConstructor() {
        int era = 1;
        int price = 10;
        int prestigeValue = 5;

        Building4 b0 = new Building4(era, price, prestigeValue);

        assertEquals(EffectType.INVENTOR_PAIR, b0.getEffectType());
        assertEquals(4, b0.getEffectId());
    }


    @Test
    @DisplayName("Testing buy method")
    void buy() {
        Player p = new Player("test");
        Building4 b4 = new Building4(1, 1,1);

        assertFalse(b4.buy(p));

        p.addFood(1);
        assertTrue(b4.buy(p));
        assertEquals(0, p.getFoodValue());

        p.addFood(1);
        assertFalse(b4.buy(p));
    }

    @Test
    @DisplayName("Testing clone method")
    void testClone() {
        int effectID = 4;
        EffectType effectType = EffectType.INVENTOR_PAIR;
        int era = 1;
        int price = 1;
        int prestigeValue = 1;
        Building4 b0 = new Building4(era, price,prestigeValue);

        Building4 b1 = (Building4) b0.clone();

        assertEquals(effectID, b1.getEffectId());
        assertEquals(effectType, b1.getEffectType());
        assertEquals(era, b1.getEra());
        assertEquals(price, b1.getPrice());
        assertEquals(prestigeValue, b1.getPrestigeValue());
    }

    @Test
    void applyEffect() {
        Player p = new Player("test");
        p.addFood(1);
        Building4 b4 = new Building4(1,1, 1);
        b4.buy(p);

        b4.applyEffect(p);
        assertEquals(0, p.getFoodValue());

        new Inventor(1,1).insert(p);
        new Inventor(1,1).insert(p);
        b4.applyEffect(p);
        assertEquals(3, p.getFoodValue());

        b4.applyEffect(p);
        assertEquals(3, p.getFoodValue());

        new Inventor(1,2).insert(p);
        new Inventor(1,2).insert(p);
        b4.applyEffect(p);
        assertEquals(6, p.getFoodValue());

        Player p2 = new Player("test2");
        new Inventor(1,1).insert(p2);
        new Inventor(1,1).insert(p2);
        p2.addFood(1);
        Building4 b4b = new Building4(1,1, 1);
        b4b.buy(p2);
        b4b.applyEffect(p2);
        assertEquals(0, p2.getFoodValue());

    }

    @Test
    void applyEffectException() {
        Player p = new Player("test");
        Building4 b4 = new Building4(1,1, 1);

        assertThrows(IllegalArgumentException.class, () -> b4.applyEffect(p));
    }
}
