package org.project.location;

import org.project.entity.enemies.Enemy;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Location {

    private final String name;

    private final List<Location> connectedLocations;
    private final List<Enemy> enemies;

    public Location(String name) {
        this.name = name;
        this.connectedLocations = new ArrayList<>();
        this.enemies = new ArrayList<>();
    }

    public Location(String name, List<Location> connectedLocations, List<Enemy> enemies) {
        this.name = name;

        this.connectedLocations =
                connectedLocations != null ? new ArrayList<>(connectedLocations) : new ArrayList<>();

        this.enemies =
                enemies != null ? new ArrayList<>(enemies) : new ArrayList<>();
    }

    public String getName() {
        return name;
    }

    public List<Location> getConnectedLocations() {
        return Collections.unmodifiableList(connectedLocations);
    }

    public List<Enemy> getEnemies() {
        return Collections.unmodifiableList(enemies);
    }

    // ------------------------------------
    // ADD / REMOVE LOCATIONS
    // ------------------------------------location

    public void connect(Location other) {
        if (other == null || other == this) return;

        if (!connectedLocations.contains(other)) {
            connectedLocations.add(other);
        }

        if (!other.connectedLocations.contains(this)) {
            other.connectedLocations.add(this);
        }
    }


    public void removeLocation(Location location) {
        connectedLocations.remove(location);
    }

    // ------------------------------------
    // ADD / REMOVE ENEMIES
    // ------------------------------------
    public void addEnemy(Enemy enemy) {
        if (enemy != null) {
            enemies.add(enemy);
        }
    }

    public void removeEnemy(Enemy enemy) {
        enemies.remove(enemy);
    }
}
