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

import it.polimi.ingsw.gc14.Model.Cards.Building.EffectType;
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 Building13Test {

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

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

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

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

        Building13 b1 = (Building13) 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 p1 = new Player("gigi");
        p1.addPrestige(10);
        Building13 b1 = new Building13(1, 10, 1);
        p1.addFood(b1.getPrice());
        b1.buy(p1);

        b1.applyEffect(p1);
        assertEquals(35, p1.getPrestigeValue());
    }

    @Test
    void applyEffectException() {
        assertThrows(IllegalArgumentException.class, () -> {
            Building13 b13 = new Building13(1, 10, 1);
            Player p = new Player("test");
            b13.applyEffect(p);
        });
    }
    @Test
    void applyEffectMultiplePlayerException() {
        Building13 b13 = new Building13(1, 10, 1);
        Player p1 = new Player("test1");
        Player p2 = new Player("test2");
        b13.buy(p1);
        assertFalse(b13.buy(p2));
    }
}