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

import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.Artist;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.Hunter;
import it.polimi.ingsw.gc14.Model.Player;
import org.junit.jupiter.api.Test;

import static it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType.ARTIST;
import static it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType.HUNTER;
import static org.junit.jupiter.api.Assertions.*;

class Building11Test {

    @Test
    void applyEffectBuyWithoutFood() {

        Player p1 = new Player("Xiaomi");
        Building11 b1 = new Building11(2, 10, 1, ARTIST, -3);
        Artist a1 = new Artist(2);
        b1.buy(p1);
        assertFalse(b1.buy(p1));
        p1.artists.add(a1);

        assertThrows(IllegalArgumentException.class, () -> {
            b1.applyEffect(p1);
        });
        p1.addFood(b1.getPrice());
        b1.buy(p1);
        b1.applyEffect(p1);
        assertEquals(-3, p1.getPrestigeValue());
    }

    @Test
    void applyEffectWithTwoCards() {
        Player p2 = new Player("Giacomo");
        Building11 b2 = new Building11(2, 10, 1, ARTIST, 4);
        Artist a2 = new Artist(2);
        Artist a3 = new Artist(2);
        p2.addFood(b2.getPrice());
        b2.buy(p2);
        p2.artists.add(a2);
        p2.artists.add(a3);


        b2.applyEffect(p2);
        assertEquals(8, p2.getPrestigeValue());
    }

    @Test
    void applyEffectTwoPlayersBuyTheSameCard() {
        Player p3 = new Player("AAAAAAAAAA");
        Player p4 = new Player("BBBBBBBBBB");
        Building11 b3 = new Building11(1, 15, 1, HUNTER, 5);
        p3.addFood(b3.getPrice());
        assertTrue(b3.buy(p3));
        p4.addFood(b3.getPrice());
        assertEquals(false, b3.buy(p4));
    }


    @Test
    void applyEffectApplyEffectWithoutBuyingFirst() {
        Player p5 = new Player("DRTFGBHJN");
        Building11 b4 = new Building11(3, 10, 1, ARTIST, 4);
        assertThrows(IllegalArgumentException.class, () -> {
            b4.applyEffect(p5);
        });
    }
}