package jnet.lib.object;

import jnet.lib.Status;
import java.io.Serializable;
import java.util.ArrayList;

public class Map implements Serializable {

    private int id;
    private String name;
    private boolean lock;
    private ArrayList<MapObject> objects;
    private ArrayList<Connection> connection;
    private int status;

    public Map(int id, String name, boolean lock, ArrayList<MapObject> objects, ArrayList<Connection> connection) {
        this.id = id;
        this.name = name;
        this.lock = lock;
        this.status = Status.NA;
        this.objects = objects;
        this.connection = connection;

    }

    public Map(String name) {
        this.name = name;
        this.lock = false;
        this.status = Status.NA;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

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

    public boolean isLock() {
        return lock;
    }

    public void setLock(boolean lock) {
        this.lock = lock;
    }

    public ArrayList<MapObject> getObjects() {
        return objects;
    }

    public void setObjects(ArrayList<MapObject> objects) {
        this.objects = objects;
    }

    public ArrayList<Connection> getConnection() {
        return connection;
    }

    public void setConnection(ArrayList<Connection> connection) {
        this.connection = connection;
    }
    
    

    public int getStatus() {
        if (getObjects().isEmpty()) {
            return Status.NA;
        }

        int status = Status.OK;

        for (MapObject object : getObjects()) {
            int objectStatus = object.getStatus();

            if (objectStatus == Status.OFFLINE) {
                return Status.OFFLINE; // Okamžitě vrátíme OFFLINE
            } else if (objectStatus == Status.WARNING) {
                status = Status.WARNING; // Možný downgrade na WARNING
            }
        }

        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

}
