package pp.monopoly.model.fields;

import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;

/**
 * Simple Manager class responsible for managing the GameBoard of Monopoly
 */
public class BoardManager {

    private List<Field> board;

    /**
     * Constructs a BoardManager
     */
    public BoardManager() {
        board = createBoard();
    }

    /**
     * Creates a Monopoly GameBoard
     * @return the List of Fields in correct  Order
     */
    private static List<Field> createBoard() {
        ArrayList<Field> fields = new ArrayList<>();

        fields.addLast(new GoField());
        fields.addLast(new BuildingProperty("Gym", 1, 600, 20));
        fields.addLast(new EventField("Hausfeier", 2));
        fields.addLast(new BuildingProperty("Sportplatz", 3, 600, 40));
        fields.addLast(new FineField("Diszi", 4, 2000));
        fields.addLast(new GateField("Südtor", 5));
        fields.addLast(new BuildingProperty("Studium+", 6, 1000, 60));
        fields.addLast(new EventField("Üvas", 7));
        fields.addLast(new BuildingProperty("PhysikHörsaal", 8, 1000, 60));
        fields.addLast(new BuildingProperty("Audimax", 9, 1200, 80));
        fields.addLast(new GulagField());
        fields.addLast(new BuildingProperty("99er", 11, 1400, 100));
        fields.addLast(new FoodField("Brandl", 12));
        fields.addLast(new BuildingProperty("12er", 13, 1400, 100));
        fields.addLast(new BuildingProperty("23er", 14, 1600, 120));
        fields.addLast(new GateField("HauptWache", 15));
        fields.addLast(new BuildingProperty("Schwimmhalle", 16, 1800, 140));
        fields.addLast(new BuildingProperty("CISM-Bahn", 17, 1800, 140));
        fields.addLast(new EventField("Marine-Welcome-Party", 18));
        fields.addLast(new BuildingProperty("Kletterturm", 19, 2000, 160));
        fields.addLast(new TestStreckeField());
        fields.addLast(new BuildingProperty("StudFBer C", 21, 2200, 180));
        fields.addLast(new EventField("Üvas", 22));
        fields.addLast(new BuildingProperty("StudFBer B", 23, 2200, 180));
        fields.addLast(new BuildingProperty("StudFBer A", 24, 2400, 200));
        fields.addLast(new GateField("Nordtor", 25));
        fields.addLast(new BuildingProperty("Cascada", 26, 2600, 220));
        fields.addLast(new BuildingProperty("Fakultätsgebäude", 27, 2600, 220));
        fields.addLast(new FoodField("Truppenküche", 28));
        fields.addLast(new BuildingProperty("Prüfungsamt", 29, 2800, 240));
        fields.addLast(new WacheField());
        fields.addLast(new BuildingProperty("Feuerwehr", 31, 3000, 260));
        fields.addLast(new BuildingProperty("SanZ", 32, 300, 260));
        fields.addLast(new EventField("Maibock", 33));
        fields.addLast(new BuildingProperty("Rechenzentrum", 34, 3200, 280));
        fields.addLast(new GateField("Osttor", 35));
        fields.addLast(new EventField("Üvas", 36));
        fields.addLast(new BuildingProperty("2er", 37, 3500, 350));
        fields.addLast(new FineField("EZM", 38, 1000));
        fields.addLast(new BuildingProperty("20er", 39, 4000, 500));

        return fields;
    }


    /**
     * Method to find the Field at specific index
     * @param index the index for which to find the field
     * @return the field at the index
     */
    public Field getFieldAtIndex(int index) {
        return board.get(index);
    }

    /**
     * Method to find the index of a Monopoly field
     * @param field the Field to get the Index of
     * @return the Index of the field
     */
    public int getIndexOfField(Field field) {
        if (board.contains(field)) return field.getId();
        else throw new NoSuchElementException();
    }
}
