package org.black_ixx.bossshop.command;

import java.util.ArrayList;

import org.black_ixx.bossshop.sale.SaleManager;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class CommandSale extends ACommandBase{

    private final ArrayList<String> mSubCommand=new ArrayList<>();
    
    public CommandSale(CommandExc exector){
        super(exector);
        this.mSubCommand.add("start");
        this.mSubCommand.add("stop");
        this.mSubCommand.add("item");
        this.mSubCommand.add("money");
        this.mSubCommand.add("points");
    }

    @Override
    public boolean execute(CommandSender pSender,String[] pArgs){
        if(!pSender.hasPermission(this.mPluginName+".sale.forsale"))
            return noPermit(pSender);
        if(!(pSender instanceof Player))
            return this.consoleNotAllow(pSender);
        Player tPlayer=(Player)pSender;
        if(pArgs.length<=1){
            String label="help";
            if(pArgs.length==1) label=pArgs[0];
            if(label.equalsIgnoreCase("help"))
                return help(pSender);
            else if(label.equalsIgnoreCase("start")){
                this.mPlugin.getSaleListener().startSaleListenrer(tPlayer);
                return true;
            }else if(label.equalsIgnoreCase("stop")){
                this.mPlugin.getSaleListener().stopSaleListenrer(tPlayer);
                return true;
            }else return unKnowChildCommand(pSender,label);
        }
        else if(pArgs.length==5){
            this.mPlugin.getManager(SaleManager.class).sale((Player)pSender,pArgs);
            return true;
        }
        return this.help(pSender);
    }

    @Override
    public ArrayList<String> getHelp(CommandSender sender,boolean pAll){
        ArrayList<String> list=new ArrayList<>();
        if(sender.hasPermission(this.mPluginName+".sale.forsale")){
            if(pAll){
                list.add("/BossShop sale [help]");
                list.add(this.C("Help.SaleHelp"));
            }
            // /BossShop sale start
            list.add(this.mMainCmdLabel+" sale start");
            list.add(this.C("Help.StartSaleWithChat"));
            // /BossShop sale start
            list.add(this.mMainCmdLabel+" sale stop");
            list.add(this.C("Help.StopSaleWithChat"));
            // /BossShop sale <售卖类型> <单次数量> <份数> <价格类型> <价格>
            list.add(this.mMainCmdLabel+" sale <"+C("Word.SellType")+"> <"+C("Word.SigleNumb")+"> <"+C("Word.PartNumb")+"> <"+C("Word.PriceType")+"> <"+C("Word.Price")+">");
            list.add(this.C("Help.SaleForsale"));
            list.add(this.C("Help.SaleSellType"));
            list.add(this.C("Help.SalePriceType"));
            list.add(this.C("Help.SaleOther"));
        }
        return list;
    }
    
    @Override
    public ArrayList<String> getSubCommand(CommandSender pSender,String[] pArgs){
        ArrayList<String> mayCmd=new ArrayList<>();
        switch(pArgs.length){
        case 1:
            return this.mSubCommand;
        case 2:
            mayCmd.add("1");
            mayCmd.add("10");
            mayCmd.add("64");
            return mayCmd;
        case 3:
            mayCmd.add("1");
            mayCmd.add("10");
            return mayCmd;
        case 4:
            mayCmd.add("money");
            mayCmd.add("points");
            return mayCmd;
        case 5:
            return mayCmd;
        }
        return this.mSubCommand;
    }

    @Override
    public int getMaxArgumentLength(){
        return 5;
    }

}
