package de.viper.survivalplus.commands;

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

public class TradeAcceptCommand implements CommandExecutor {

    private final TradeManager tradeManager;
    private final SurvivalPlus plugin;

    public TradeAcceptCommand(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 target)) {
            senderS.sendMessage(plugin.getLangConfig().getString("only-players", "§cNur Spieler können diesen Befehl ausführen!"));
            return true;
        }

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

        tradeManager.acceptTrade(target, args[0]);
        return true;
    }
}