package net.cobem.grizzly.habbohotel.users.badges;

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

import java.sql.ResultSet;

public class BadgeObject {
    public int ID;
    public int User;
    public int Slot;

    public String Code;

    public boolean Equipped;


    public BadgeObject(ResultSet Set) {
        try {
            this.ID = 0;
            this.User = Set.getInt("user_id");
            this.Slot = Set.getInt("badge_slot");

            this.Code = Set.getString("badge_id");

            this.Equipped = (Set.getInt("badge_slot") != 0);
        } catch (Exception ex) {
        }
    }

    public BadgeObject(int User, String Code) {
        DatabaseResult GetBadges = Grizzly.getStorage().query("SELECT * FROM user_badges WHERE user_id = '" + ID + "' AND badge_id = '" + Code + "'");

        ResultSet Set = GetBadges.getTable();

        try {
            while (Set.next()) {
                this.ID = 0;
                this.User = Set.getInt("user_id");
                this.Slot = Set.getInt("badge_slot");

                this.Code = Set.getString("badge_id");

                this.Equipped = (Set.getInt("badge_slot") != 0);
            }
        } catch (Exception ex) {
        }
    }

    public boolean append() {
        Grizzly.getStorage().execute("UPDATE user_badges SET badge_slot = '" + this.Slot + "' WHERE badge_id = '" + this.Code + "' AND user_id = '" + this.User + "'");
        return true;
    }

}
