package it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters;

import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType;
import it.polimi.ingsw.gc14.Model.Orders.Order2;
import it.polimi.ingsw.gc14.Model.Player;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;

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

class InventorTest {

    @Test
    void icon() {
        Inventor i = new Inventor(1, 5);

        assertEquals(5, i.Icon());
    }

    @Test
    void testToString() {
        Inventor i = new Inventor(1, 5);
        String s = i.toString();

        assertNotNull(s);
        assertTrue(s.contains(CharacterType.INVENTOR.toString()));
        assertTrue(s.contains("Symbol:"));
        assertTrue(s.contains("5"));
    }

    @Test
    void testClone() {
        Inventor i = new Inventor(1, 5, 3);
        Inventor clone = (Inventor) i.clone();

        assertNotNull(clone);
        assertNotSame(i, clone);
        assertEquals(i.getEra(), clone.getEra());
        assertEquals(i.getType(), clone.getType());
        assertEquals(i.Icon(), clone.Icon());
        assertEquals(i.getNMin(), clone.getNMin());
    }

    @Test
    void insert() {
        Player p = new Player("test");
        Inventor i = new Inventor(1, 5);

        assertEquals(0, p.inventors.size());

        i.insert(p);

        assertEquals(1, p.inventors.size());
        assertTrue(p.inventors.contains(i));

        Inventor i2 = new Inventor(1, 7);
        i2.insert(p);

        assertEquals(2, p.inventors.size());
        assertTrue(p.inventors.contains(i2));
    }

    @Test
    void constructorTest() {
        Inventor i = new Inventor(1, 5);

        assertEquals(1, i.getEra());
        assertEquals(CharacterType.INVENTOR, i.getType());
        assertEquals(5, i.Icon());
        assertEquals(0, i.getNMin());
        assertFalse(i.IsEventCard());
    }

    @Test
    void constructorWithNMinTest() {
        Inventor i = new Inventor(1, 5, 3);

        assertEquals(1, i.getEra());
        assertEquals(CharacterType.INVENTOR, i.getType());
        assertEquals(5, i.Icon());
        assertEquals(3, i.getNMin());
        assertFalse(i.IsEventCard());
    }

    @Test
    void negativeIcon() {
        assertThrows(IllegalArgumentException.class, () -> {
            new Inventor(1, -1);
        });
    }

    @Test
    void iconGreaterThanNine() {
        assertThrows(IllegalArgumentException.class, () -> {
            new Inventor(1, 10);
        });
    }

    @Test
    void negativeIconWithNMin() {
        assertThrows(IllegalArgumentException.class, () -> {
            new Inventor(1, -1, 3);
        });
    }

    @Test
    void iconGreaterThanNineWithNMin() {
        assertThrows(IllegalArgumentException.class, () -> {
            new Inventor(1, 10, 3);
        });
    }
}