// • ▌ ▄ ·.  ▄▄▄·  ▄▄ • ▪   ▄▄· ▄▄▄▄·  ▄▄▄·  ▐▄▄▄  ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀  █▪▀▀▀ ▀  ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀  ▀  ▀ ▀▀  █▪ ▀▀▀
//      Magicbane Emulator Project © 2013 - 2022
//                www.magicbane.com


package engine.objects;

import engine.gameManager.DbManager;
import org.pmw.tinylog.Logger;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;

public class ItemBase {

    public static ItemBase GOLD_ITEM_BASE = null;
    public static HashMap<Integer, ItemBase> _itemBaseByUUID = new HashMap<>();

    public final int uuid;
    private final int modTable;

    public ItemBase(ResultSet rs) throws SQLException {

        this.uuid = rs.getInt("ID");
        this.modTable = rs.getInt("modTable");

        ItemTemplate template = ItemTemplate.templates.get(this.getUUID());

        if (template == null)
            Logger.error(this.getUUID() + " null template");

    }

    public static void addToCache(ItemBase itemBase) {

        _itemBaseByUUID.put(itemBase.uuid, itemBase);

        ItemTemplate template = ItemTemplate.templates.get(itemBase.uuid);

        if (template == null)
            Logger.error("Null template for: " + itemBase.uuid);
    }

    public static ItemBase getItemBase(int uuid) {

        return _itemBaseByUUID.get(uuid);
    }

    public static HashMap<Integer, ItemBase> getUUIDCache() {
        return _itemBaseByUUID;
    }

    public static void loadAllItemBases() {
        DbManager.ItemBaseQueries.LOAD_ALL_ITEMBASES();
    }


    public int getModTable() {
        return modTable;
    }

    public final int getUUID() {
        return uuid;
    }

}
