package net.cobem.grizzly.habbohotel.furni;

import gnu.trove.map.hash.THashMap;
import net.cobem.grizzly.Grizzly;
import net.cobem.grizzly.storage.DatabaseResult;

import java.sql.ResultSet;
import java.sql.SQLException;


public class FurnitureHandler {
    private THashMap<Integer, Furniture> Furniture;

    private TeleporterHandler TeleporterHandler;

    public FurnitureHandler() throws SQLException {
        Grizzly.write("Loading furniture... ", true, false);

        Furniture = new THashMap<>();

        DatabaseResult GrabFurni = Grizzly.getStorage().query("SELECT * FROM furniture");

        ResultSet Furni = GrabFurni.getTable();

        while (Furni.next()) {
            Furniture.put(Furni.getInt("id"), new Furniture(Furni));
        }

        Grizzly.write(Furniture.size(), false, true);

        TeleporterHandler = new TeleporterHandler();
    }

    public Furniture getByID(int ID) {
        if (Furniture.containsKey(ID)) {
            return Furniture.get(ID);
        }

        return null;
    }

    public TeleporterHandler getTeleporters() {
        return this.TeleporterHandler;
    }
}
