package pw.yumc.Residence.commandsub;

import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import com.bekvon.bukkit.residence.protection.ClaimedResidence;
import com.bekvon.bukkit.residence.protection.ResidenceManager;

import cn.citycraft.PluginHelper.commands.BaseCommand;
import pw.yumc.Residence.ResidenceMain;
import pw.yumc.Residence.text.Language;

public class CommandBank extends BaseCommand {
    ResidenceMain plugin;

    public CommandBank(final ResidenceMain plugin) {
        super("b");
        this.plugin = plugin;
        setMinimumArguments(2);
        setOnlyPlayerExecutable();
        setPossibleArguments("[deposit(存入)|withdraw(取出)] 金额");
    }

    @Override
    public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
        final Player player = (Player) sender;
        final boolean resadmin = (command != null);
        final ResidenceManager rmanager = plugin.getResidenceManager();
        final Language language = plugin.getLanguage();
        final ClaimedResidence res = rmanager.getByName(plugin.getPlayerListener().getCurrentResidenceName(player.getName()));
        if (res == null) {
            player.sendMessage(ChatColor.RED + language.getPhrase("NotInResidence"));
            return;
        }
        int amount = 0;
        try {
            amount = Integer.parseInt(args[1]);
        } catch (final Exception ex) {
            player.sendMessage(ChatColor.RED + language.getPhrase("InvalidAmount"));
            return;
        }
        final String subcmd = args[0];
        switch (subcmd) {
        case "deposit":
            res.getBank().deposit(player, amount, resadmin);
        case "withdraw":
            res.getBank().withdraw(player, amount, resadmin);
        }
    }

}
