package de.viper.survivalplus.commands;

import de.viper.survivalplus.SurvivalPlus;
import de.viper.survivalplus.report.ReportManager;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class ClearReportCommand implements CommandExecutor {

    private final SurvivalPlus plugin;
    private final ReportManager reportManager;

    public ClearReportCommand(SurvivalPlus plugin, ReportManager reportManager) {
        this.plugin = plugin;
        this.reportManager = reportManager;
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (!(sender instanceof Player player)) {
            sender.sendMessage(plugin.getLangConfig().getString("clearreport.only-players", "§cNur Spieler können diesen Befehl ausführen!"));
            return true;
        }

        if (!player.hasPermission("survivalplus.report.clear")) {
            player.sendMessage(plugin.getLangConfig().getString("no-permission", "§cDu hast keine Berechtigung!"));
            return true;
        }

        if (args.length != 1) {
            player.sendMessage(plugin.getLangConfig().getString("clearreport.usage", "§cVerwendung: /clearreport <Spieler>"));
            return true;
        }

        String targetName = args[0];
        reportManager.clearReports(targetName);

        player.sendMessage(plugin.getLangConfig().getString("clearreport.cleared", "§aReports von %player% wurden gelöscht.").replace("%player%", targetName));

        return true;
    }
}
