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.*;
import it.polimi.ingsw.gc14.Model.Player;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;

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

class Building10Test {

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

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

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

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

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

        int Era = 1;
        int Nset = 2;

        ArrayList<Artist> Artists = new ArrayList<>();
        ArrayList<Builder> Builders = new ArrayList<>();
        ArrayList<Gatherer> Gatherers = new ArrayList<>();
        ArrayList<Hunter> Hunters = new ArrayList<>();
        ArrayList<Inventor> Inventors = new ArrayList<>();
        ArrayList<Shaman> Shamans = new ArrayList<>();

        for(int i = 0; i < Nset; i++) {
            Artists.add(new Artist(Era));
            Builders.add(new Builder(Era, 0, 0));
            Gatherers.add(new Gatherer(Era));
            Hunters.add(new Hunter(Era, true));
            Inventors.add(new Inventor(Era, 1));
            Shamans.add(new Shaman(Era, 1));
        }

        p.artists.addAll(Artists);
        p.builders.addAll(Builders);
        p.gatherers.addAll(Gatherers);
        p.hunters.addAll(Hunters);
        p.inventors.addAll(Inventors);
        p.shamans.addAll(Shamans);

        b10.applyEffect(p);
        assertEquals(Nset * 6, p.getPrestigeValue());
    }

    @Test
    void applyEffectException() {
        assertThrows(IllegalArgumentException.class, () -> {
            Building10 b10 = new Building10(1, 1, 1);
            Player p = new Player("test");
            b10.applyEffect(p);
        });
    }

    @Test
    void applyEffectMultiplePlayerException() {
            Building10 b10 = new Building10(1, 1, 1);
            Player p1 = new Player("test1");
            Player p2 = new Player("test2");
            b10.buy(p1);
            assertFalse(b10.buy(p2));
    }
}