/*
 *   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.commands;

import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.world.Color;
import de.steamwar.bausystem.world.regions.GlobalRegion;
import de.steamwar.bausystem.world.regions.Region;
import de.steamwar.command.SWCommand;
import org.bukkit.entity.Player;


public class CommandColor extends SWCommand {

    private static CommandColor instance = null;

    public CommandColor() {
        super("color");
        instance = this;
    }

    public static CommandColor getInstance() {
        return instance;
    }

    @Register(help = true)
    public void genericHelp(Player p, String... args) {
        p.sendMessage("§8/§ecolor §8[§7Color§8] §8- §7Setze die Farbe der Region");
        p.sendMessage("§8/§ecolor §8[§7Color§8] §8[§7Type§8] §8- §7Setze die Farbe der Region oder Global");
    }

    @Register
    public void genericColor(Player p, Color color) {
        genericColorSet(p, color, ColorizationType.LOCAL);
    }

    @Register
    public void genericColorSet(Player p, Color color, ColorizationType colorizationType) {
        if (!permissionCheck(p)) {
            return;
        }
        if (colorizationType == ColorizationType.GLOBAL) {
            Region.setGlobalColor(color);
            p.sendMessage(BauSystem.PREFIX + "Alle Regions farben auf §e" + color.name().toLowerCase() + "§7 gesetzt");
            return;
        }
        Region region = Region.getRegion(p.getLocation());
        if (GlobalRegion.isGlobalRegion(region)) {
            p.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner Region");
            return;
        }
        region.setColor(color);
        p.sendMessage(BauSystem.PREFIX + "Regions farben auf §e" + color.name().toLowerCase() + "§7 gesetzt");
    }

    @Register
    public void genericColorSet(Player p, ColorizationType colorizationType, Color color) {
        genericColorSet(p, color, colorizationType);
    }

    private boolean permissionCheck(Player p) {
        if (!BauSystem.getOwner().equals(p.getUniqueId())) {
            p.sendMessage(BauSystem.PREFIX + "§cDies ist nicht deine Welt!");
            return false;
        } else {
            return true;
        }
    }

    public enum ColorizationType {
        LOCAL,
        GLOBAL
    }

}