package net.cobem.grizzly.habbohotel.catalog;

import net.cobem.grizzly.Grizzly;
import net.cobem.grizzly.storage.DatabaseResult;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class CatalogPage {
    public int ID;
    public int Parent;
    public int Order;
    public int IconColor;
    public int IconImage;
    public int Rank;

    public CatalogLayout Layout;

    public String Title;

    public String Header;
    public String Description;

    public boolean Enabled;

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

    private boolean FillClass(ResultSet Set) {
        try {
            this.ID = Set.getInt("id");
            this.Parent = Set.getInt("parent_id");
            this.Order = Set.getInt("order_num");
            this.IconColor = Set.getInt("icon_color");
            this.IconImage = Set.getInt("icon_image");
            this.Rank = Set.getInt("min_rank");

            this.Layout = CatalogLayout.valueOf(Set.getString("page_layout"));

            this.Title = Set.getString("caption");
            this.Header = Set.getString("page_headline");
            this.Description = Set.getString("page_text1");

            this.Enabled = (Set.getInt("enabled") == 1);
            return true;
        } catch (SQLException Ex) {
            return false;
        }
    }

    public boolean containsLTD() {
        for (CatalogItem Item : Grizzly.getHabboHotel().getCatalog().getItems(ID).values()) {
            if (Item.LTD) {
                return true;
            }
        }

        return false;
    }
}
