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;

import java.util.List;

public class ShowReportCommand implements CommandExecutor {

    private final SurvivalPlus plugin;
    private final ReportManager reportManager;

    public ShowReportCommand(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("showreport.only-players", "§cNur Spieler können diesen Befehl ausführen!"));
            return true;
        }

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

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

        String targetName = args[0];
        List<String> reports = reportManager.getReports(targetName);

        if (reports.isEmpty()) {
            player.sendMessage(plugin.getLangConfig().getString("showreport.no-reports", "§aEs wurden keine Reports für diesen Spieler gefunden."));
            return true;
        }

        player.sendMessage("§6--- Reports für Spieler " + targetName + " ---");
        reports.forEach(r -> player.sendMessage("§7" + r));

        return true;
    }
}
