package org.project.location;

import org.project.entity.enemies.Enemy;

import java.util.ArrayList;

public class Location {
    private String name;
    private ArrayList<Location> locations;
    private ArrayList<Enemy> enemies;

    public Location(String name, ArrayList<Location> locations, ArrayList<Enemy> enemies) {
        this.name = name;
        this.locations = locations;
        this.enemies = enemies;
    }

    public String getName() {
        return name;
    }

    public ArrayList<Location> getLocations() {
        return locations;
    }

    public ArrayList<Enemy> getEnemies() {
        return enemies;
    }

    /**
     *This method initializes the game world by creating locations
     * and establishing their connections.
     * @return The starting location.
     */
    public static Location generateMap() {
        // Create individual locations
        Location village = new Location("Village", new ArrayList<>(), new ArrayList<>());
        Location forest = new Location("Forest", new ArrayList<>(), new ArrayList<>());
        Location cave = new Location("Cave", new ArrayList<>(), new ArrayList<>());
        Location dungeon = new Location("Dungeon", new ArrayList<>(), new ArrayList<>());
        Location castle = new Location("Castle", new ArrayList<>(), new ArrayList<>());

        // Establishing connections between locations
        // Village <-> Forest
        village.addConnection(forest);
        forest.addConnection(village);

        // Forest <-> Cave
        forest.addConnection(cave);
        cave.addConnection(forest);

        // Cave <-> Dungeon
        cave.addConnection(dungeon);
        dungeon.addConnection(cave);

        // Dungeon <-> Castle
        dungeon.addConnection(castle);
        castle.addConnection(dungeon);

        return village; // Start of the journey
    }

    //Helper method to add a connection to avoid direct list manipulation from outside.
    public void addConnection(Location location) {
        if (!this.locations.contains(location)) {
            this.locations.add(location);
        }
    }
}
