/*
 *   This file is a part of the SteamWar software.
 *
 *   Copyright (C) 2025 SteamWar.de-Serverteam
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU Affero General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *   GNU Affero General Public License for more details.
 *
 *   You should have received a copy of the GNU Affero General Public License
 *   along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package de.steamwar.bausystem.features.hotbar;

import de.steamwar.bausystem.BauSystem;
import de.steamwar.command.SWCommand;
import de.steamwar.inventory.SWInventory;
import de.steamwar.linkage.Linked;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

@Linked
public class HotbarCommand extends SWCommand {

    public HotbarCommand() {
        super("hotbar", "hb");
        addDefaultHelpMessage("HOTBAR_HELP_GENERIC");
    }

    @Register(value = "load", description = "HOTBAR_HELP_LOAD")
    public void loadHotbar(@Validator Player p) {
        DefaultHotbar.setHotbar(p);
        BauSystem.MESSAGE.send("HOTBAR_LOADED", p);
    }

    @Register(value = "save", description = "HOTBAR_HELP_SAVE")
    public void saveHotbar(Player p) {
        DefaultHotbar.updateHotbar(p);
        BauSystem.MESSAGE.send("HOTBAR_SAVED", p);
    }

    @Register(value = "show", description = "HOTBAR_HELP_SHOW")
    public void showHotbar(Player p) {
        SWInventory inv = new SWInventory(p, 18, BauSystem.MESSAGE.parse("HOTBAR_INVENTORY", p));
        ItemStack[] hotbar = DefaultHotbar.getItems(p);
        for (int i = 0; i < hotbar.length; i++) {
            if (hotbar[i] == null) continue;
            inv.setItem(i, hotbar[i], clickType -> {
            });
        }
        inv.open();
    }
}
