package it.polimi.ingsw.gc14.Model.GamePackage;

import it.polimi.ingsw.gc14.Model.Player;
import it.polimi.ingsw.gc14.Model.Slot;
import org.junit.jupiter.api.Test;

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

class CurrentStateTest {

    @Test
    void getCurrentPlayer() {
        Player p = new Player("test");
        Slot s = new Slot('A');
        CurrentState curr = new CurrentState();
        curr.PlayerUpdate(p, s);
        assertEquals(p, curr.getCurrentPlayer());
    }

    @Test
    void getSlot() {
        Player p = new Player("test");
        Slot s = new Slot('A');
        CurrentState curr = new CurrentState();
        curr.PlayerUpdate(p, s);
        assertEquals(s, curr.getSlot());
    }

    @Test
    void getEra() {
        Player p = new Player("test");
        Slot s = new Slot('A');
        CurrentState curr = new CurrentState();
        curr.PlayerUpdate(p, s);
        curr.EraUpdate();
        assertEquals(2, curr.getEra());
    }

    @Test
    void getRound() {
        Player p = new Player("test");
        Slot s = new Slot('A');
        CurrentState curr = new CurrentState();
        curr.PlayerUpdate(p, s);
        curr.RoundUpdate();
        assertEquals(2, curr.getRound());
    }

    @Test
    void getNUpper() {
        Player p = new Player("test");
        Slot s = new Slot('A');
        CurrentState curr = new CurrentState();
        curr.PlayerUpdate(p, s);
        curr.UpperDrawn();
        assertEquals(-1, curr.getNUpper());
    }

    @Test
    void getNLower() {
        Player p = new Player("test");
        Slot s = new Slot('A');
        CurrentState curr = new CurrentState();
        curr.PlayerUpdate(p, s);
        curr.LowerDrawn();
        assertEquals(-1, curr.getNLower());
    }

    @Test
    void getGameStage() {
        Player p = new Player("test");
        Slot s = new Slot('A');
        GameStages g = GameStages.RESOLVING_ACTIONS;
        CurrentState curr = new CurrentState();
        curr.PlayerUpdate(p, s);
        curr.GameStageUpdate(g);
        assertEquals(g, curr.getGameStage());
    }

    @Test
    void eraUpdate() {
        Player p = new Player("test");
        Slot s = new Slot('A');
        CurrentState curr = new CurrentState();
        curr.PlayerUpdate(p, s);
        curr.EraUpdate();
        assertEquals(2, curr.getEra());
    }

    @Test
    void roundUpdate() {
        Player p = new Player("test");
        Slot s = new Slot('A');
        CurrentState curr = new CurrentState();
        curr.PlayerUpdate(p, s);
        curr.RoundUpdate();
        assertEquals(2, curr.getRound());
    }

    @Test
    void upperDrawn() {
        Player p = new Player("test");
        Slot s = new Slot('A');
        CurrentState curr = new CurrentState();
        curr.PlayerUpdate(p, s);
        curr.UpperDrawn();
        assertEquals(-1, curr.getNUpper());
    }

    @Test
    void lowerDrawn() {
        Player p = new Player("test");
        Slot s = new Slot('A');
        CurrentState curr = new CurrentState();
        curr.PlayerUpdate(p, s);
        curr.LowerDrawn();
        curr.LowerDrawn();
        assertEquals(-2, curr.getNLower());
    }

    @Test
    void gameStageUpdate() {
        Player p = new Player("test");
        Slot s = new Slot('A');
        GameStages g = GameStages.RESOLVING_ACTIONS;
        CurrentState curr = new CurrentState();
        assertEquals(GameStages.WAITING, curr.getGameStage());
        curr.PlayerUpdate(p, s);
        curr.GameStageUpdate(g);
        assertEquals(GameStages.RESOLVING_ACTIONS, curr.getGameStage());
    }

    @Test
    void playerUpdate() {
        Player p = new Player("test");
        Slot s = new Slot('C');
        CurrentState curr = new CurrentState();
        curr.PlayerUpdate(p, s);
        assertEquals(p, curr.getCurrentPlayer());
        assertEquals(s, curr.getSlot());
    }

    @Test
    void constructor() {
        CurrentState curr = new CurrentState();
        assertNull(curr.getCurrentPlayer());
        assertNull(curr.getSlot());
        assertEquals(1, curr.getEra());
        assertEquals(1, curr.getRound());
        assertEquals(0, curr.getNUpper());
        assertEquals(0, curr.getNLower());
        assertEquals(GameStages.WAITING, curr.getGameStage());
    }
}