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.Builder;
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 Building8Test {

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

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

        assertEquals(EffectType.FINAL, b0.getEffectType());
        assertEquals(8, b0.getEffectId());
    }

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

        Building8 b1 = (Building8) 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() {
        Building8 b8 = new Building8(1, 1, 1);
        Player p = new Player("test");
        p.addFood(b8.getPrice());
        b8.buy(p);

        int Era = 1;
        int PrestigeMul = 1;
        Builder builder1 = new Builder(Era, 1, PrestigeMul);
        p.builders.add(builder1);

        b8.applyEffect(p);

        assertEquals(1, p.buildingCards.stream().filter(x -> x.getEffectId() == 8).count());
        assertEquals(PrestigeMul * 2 * p.buildingCards.stream().filter(x -> x.getEffectId() == 8).count(), p.getPrestigeValue());

        Builder b2 = new Builder(Era, 1, PrestigeMul);
        p.builders.add(b2);
        b8.applyEffect(p);

        assertEquals(2 + 4, p.getPrestigeValue());
    }

    @Test
    @DisplayName("Exception Test")
    void ExceptionTest() {
        Player p = new Player("test");
        Building8 b8 = new Building8(1, 1, 1);
        Building0 b0 = new Building0(1, 1, 1);
        p.buildingCards.add(b0);

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