package net.cobem.grizzly.habbohotel.catalog;

import net.cobem.grizzly.Grizzly;
import net.cobem.grizzly.habbohotel.furni.Furniture;

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


public class CatalogItem {
    public int ID;
    public int Page;
    public int Cost;
    public int PixelCost;
    public int CurrencyCost;
    public int Quantity;
    public int Unique;

    public String Title;

    public Boolean LTD;

    public int LTD_Stock;
    public int LTD_Purchased;

    public CatalogItem(ResultSet Page) {
        FillClass(Page);
    }

    private boolean FillClass(ResultSet Set) {
        try {
            this.ID = Set.getInt("id");
            this.Page = Set.getInt("page_id");
            this.Cost = Set.getInt("cost_credits");
            this.PixelCost = Set.getInt("cost_pixels");
            this.CurrencyCost = Set.getInt("cost_snow");
            this.Quantity = Set.getInt("amount");
            this.Unique = Set.getInt("item_ids");

            this.LTD = (Set.getInt("ltd") == 1);

            this.Title = Set.getString("catalog_name");

            this.LTD_Stock = Set.getInt("ltd_stock");
            this.LTD_Purchased = Set.getInt("ltd_purchased");

            return true;
        } catch (SQLException Ex) {
            return false;
        }
    }

    public Furniture getBase() {
        return Grizzly.getHabboHotel().getFurniture().getByID(this.Unique);
    }

    public String getPresetFlag() {
        if (Title.split("_").length >= 3)
        {
            return Title.split("_")[2];
        }

        return "";
    }
}
