package org.studiorailgun.sim.space;

import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;

import org.studiorailgun.Globals;
import org.studiorailgun.sim.character.Character;
import org.studiorailgun.sim.item.Item;
import org.studiorailgun.sim.writing.GroupDescriber;

/**
 * An area contains characters, items, etc.
 * It can also contain other areas recursively.
 */
public class Location {

    /**
     * The id of the location
     */
    int id;

    /**
     * The type of the location
     */
    String type;
    
    /**
     * The characters currently in this region
     */
    transient List<Character> chars = new LinkedList<Character>();

    /**
     * The items in the location
     */
    transient List<Item> items = new LinkedList<Item>();


    /**
     * Describes the location
     */
    public void describe(){
        System.out.println("You are in a " + this.type + ".");
        if(chars.size() > 1){
            List<Character> filtered = chars.stream().filter(chara -> chara != Globals.playerCharacter).collect(Collectors.toList());
            GroupDescriber.summarize(filtered);
        }
        if(items.size() > 0){
            System.out.println("There are " + items.size() + " items in the " + this.type + ".");
        }
    }

    /**
     * Constructor
     * @param type The type of the location
     */
    public Location(String type){
        this.type = type;
    }

    /**
     * Removes a character from this location
     * @param character The character
     */
    public void removeCharacter(Character character){
        this.chars.remove(character);
    }

    /**
     * Adds a character to this location
     * @param character The character
     */
    public void addCharacter(Character character){
        this.chars.add(character);
    }

    /**
     * Gets the characters in this location
     * @return The characters in this location
     */
    public List<Character> getChars() {
        return chars;
    }

    /**
     * Sets the list of characters in this location
     * @param chars The list of characters in this location
     */
    public void setChars(List<Character> chars) {
        this.chars = chars;
    }

    /**
     * Gets the list of items in this location
     * @return The list of items in this location
     */
    public List<Item> getItems() {
        return items;
    }

    /**
     * Sets the list of items in this location
     * @param items The list of items in this location
     */
    public void setItems(List<Item> items) {
        this.items = items;
    }

    /**
     * Gets the type of the location
     * @return The type of the location
     */
    public String getType() {
        return type;
    }

    /**
     * Sets the type of the location
     * @param type The type of the location
     */
    public void setType(String type) {
        this.type = type;
    }

    /**
     * Gets the id of this location
     * @return The id of this location
     */
    public int getId() {
        return id;
    }

    
    
    

}
