package org.project.location;

import org.project.entity.enemies.Enemy;
import org.project.entity.enemies.Goblin;
import org.project.entity.enemies.Skeleton;
import org.project.entity.enemies.Vampire;
import org.project.item.weapons.Sword;

import java.util.ArrayList;
import java.util.Random;

public class Location {

    private String name;
    private ArrayList<Enemy> enemies;
    private static Random random = new Random();
    private ArrayList<Location> locations;

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

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

    public void generateEnemies(){
        int enemyCount = random.nextInt(2) + 2;
        for (int i = 0; i < enemyCount; i++) {
            int type = random.nextInt(3);
            switch (type){
                case 0 :
                    enemies.add(new Goblin("Goblin", 40, 15, new Sword(), 50));
                    break;
                case 1 :
                    enemies.add(new Skeleton("Skeleton", 50, 20, new Sword(), 60));
                    break;
                case 2 :
                    enemies.add(new Vampire("Vampire", 55,25, new Sword(), 70));
                    break;
            }
        }
    }

    public Enemy getRandomEnemy(){
        if(enemies.isEmpty() ){
            return null;
        }
        return enemies.get(random.nextInt(enemies.size()));
    }

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

    public boolean hasEnemies(){
        return !enemies.isEmpty();
    }

    public String getName() {
        return name;
    }

    public void setName(){
        this.name = name;
    }

    public void addLocation(Location location){
        this.locations.add(location);
    }

    public void addEnemy(Enemy enemy){
        this.enemies.add(enemy);
    }

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

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