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

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 Order4Test {

    @Test
    void effectZero() {
        Player p = new Player("Marco");
        Order4 order = new Order4(new ArrayList<>());

        int initialFood = p.getFoodValue();

        order.effect(p, 0);

        assertEquals(initialFood + 2, p.getFoodValue());
    }

    @Test
    void effectOne() {
        Player p = new Player("Luca");
        Order4 order = new Order4(new ArrayList<>());

        int initialFood = p.getFoodValue();

        order.effect(p, 1);

        assertEquals(initialFood + 1, p.getFoodValue());
    }

    @Test
    void effectTwo() {
        Player p = new Player("Antonio");
        Order4 order = new Order4(new ArrayList<>());

        int initialFood = p.getFoodValue();
        int initialPrestige = p.getPrestigeValue();

        order.effect(p, 2);

        assertEquals(initialFood, p.getFoodValue());
        assertEquals(initialPrestige, p.getPrestigeValue());
    }

    @Test
    void effectThreeWithFood() {
        Player p = new Player("Giovanni");
        Order4 order = new Order4(new ArrayList<>());

        p.addFood(1);

        order.effect(p, 3);

        assertEquals(0, p.getFoodValue());
        assertEquals(-2, p.getPrestigeValue());
    }

    @Test
    void effectThreeWithoutFood() {
        Player p = new Player("test");
        Order4 order = new Order4(new ArrayList<>());

        int initialFood = p.getFoodValue();
        int initialPrestige = p.getPrestigeValue();

        order.effect(p, 3);

        assertEquals(initialFood, p.getFoodValue());
        assertEquals(initialPrestige, p.getPrestigeValue());
    }

    @Test
    void effectWrongIndexHigh() {
        Player p = new Player("Marco");
        Order4 order = new Order4(new ArrayList<>());

        assertThrows(IndexOutOfBoundsException.class, () -> order.effect(p, 4));
    }

    @Test
    void effectWrongIndexLow() {
        Player p = new Player("Marco");
        Order4 order = new Order4(new ArrayList<>());

        assertThrows(IndexOutOfBoundsException.class, () -> order.effect(p, -1));
    }
}