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

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

        int initialFood = p.getFoodValue();

        order.effect(p, 0);

        assertEquals(initialFood + 3, p.getFoodValue());
        assertEquals(0, p.getPrestigeValue());
    }

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

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

        order.effect(p, 1);

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

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

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

        order.effect(p, 2);

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

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

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

        order.effect(p, 3);

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

    @Test
    void effectFourWithFood() {
        Player p = new Player("Francesco");
        Order5 order = new Order5(new ArrayList<>());

        p.addFood(1);

        order.effect(p, 4);

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

    @Test
    void effectFourWithoutFood() {
        Player p = new Player("Giulio");
        Order5 order = new Order5(new ArrayList<>());

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

        order.effect(p, 4);

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

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

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

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

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