package de.viper.survivalplus.commands;

import de.viper.survivalplus.SurvivalPlus;
import de.viper.survivalplus.trade.TradeManager;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class TradeCommand implements CommandExecutor {

    private final SurvivalPlus plugin;
    private final TradeManager tradeManager;

    public TradeCommand(SurvivalPlus plugin, TradeManager tradeManager) {
        this.plugin = plugin;
        this.tradeManager = tradeManager;
    }

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

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

        Player target = Bukkit.getPlayerExact(args[0]);
        if (target == null || !target.isOnline()) {
            sender.sendMessage(plugin.getLangConfig().getString("trade.player-not-online", "§cDieser Spieler ist nicht online!"));
            return true;
        }

        tradeManager.requestTrade(sender, target);
        return true;
    }
}