// 
// Decompiled by Procyon v0.6.0
// 

package org.jline.console;

import java.util.Iterator;
import java.util.Collection;
import java.util.Map;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.regex.Pattern;
import java.util.TreeMap;
import org.jline.utils.AttributedString;
import java.util.List;

public class CmdDesc
{
    private List<AttributedString> mainDesc;
    private List<ArgDesc> argsDesc;
    private TreeMap<String, List<AttributedString>> optsDesc;
    private Pattern errorPattern;
    private int errorIndex;
    private boolean valid;
    private boolean command;
    private boolean subcommand;
    private boolean highlighted;
    
    public CmdDesc() {
        this.errorIndex = -1;
        this.valid = true;
        this.command = false;
        this.subcommand = false;
        this.highlighted = true;
        this.command = false;
    }
    
    public CmdDesc(final boolean valid) {
        this.errorIndex = -1;
        this.valid = true;
        this.command = false;
        this.subcommand = false;
        this.highlighted = true;
        this.valid = valid;
    }
    
    public CmdDesc(final List<ArgDesc> argsDesc) {
        this(new ArrayList<AttributedString>(), argsDesc, new HashMap<String, List<AttributedString>>());
    }
    
    public CmdDesc(final List<ArgDesc> argsDesc, final Map<String, List<AttributedString>> optsDesc) {
        this(new ArrayList<AttributedString>(), argsDesc, optsDesc);
    }
    
    public CmdDesc(final List<AttributedString> mainDesc, final List<ArgDesc> argsDesc, final Map<String, List<AttributedString>> optsDesc) {
        this.errorIndex = -1;
        this.valid = true;
        this.command = false;
        this.subcommand = false;
        this.highlighted = true;
        this.argsDesc = new ArrayList<ArgDesc>(argsDesc);
        this.optsDesc = new TreeMap<String, List<AttributedString>>(optsDesc);
        if (mainDesc.isEmpty() && optsDesc.containsKey("main")) {
            this.mainDesc = new ArrayList<AttributedString>(optsDesc.get("main"));
            this.optsDesc.remove("main");
        }
        else {
            this.mainDesc = new ArrayList<AttributedString>(mainDesc);
        }
        this.command = true;
    }
    
    public boolean isValid() {
        return this.valid;
    }
    
    public boolean isCommand() {
        return this.command;
    }
    
    public void setSubcommand(final boolean subcommand) {
        this.subcommand = subcommand;
    }
    
    public boolean isSubcommand() {
        return this.subcommand;
    }
    
    public void setHighlighted(final boolean highlighted) {
        this.highlighted = highlighted;
    }
    
    public boolean isHighlighted() {
        return this.highlighted;
    }
    
    public CmdDesc mainDesc(final List<AttributedString> mainDesc) {
        this.mainDesc = new ArrayList<AttributedString>(mainDesc);
        return this;
    }
    
    public void setMainDesc(final List<AttributedString> mainDesc) {
        this.mainDesc = new ArrayList<AttributedString>(mainDesc);
    }
    
    public List<AttributedString> getMainDesc() {
        return this.mainDesc;
    }
    
    public TreeMap<String, List<AttributedString>> getOptsDesc() {
        return this.optsDesc;
    }
    
    public void setErrorPattern(final Pattern errorPattern) {
        this.errorPattern = errorPattern;
    }
    
    public Pattern getErrorPattern() {
        return this.errorPattern;
    }
    
    public void setErrorIndex(final int errorIndex) {
        this.errorIndex = errorIndex;
    }
    
    public int getErrorIndex() {
        return this.errorIndex;
    }
    
    public List<ArgDesc> getArgsDesc() {
        return this.argsDesc;
    }
    
    public boolean optionWithValue(final String option) {
        for (final String key : this.optsDesc.keySet()) {
            if (key.matches("(^|.*\\s)" + option + "($|=.*|\\s.*)")) {
                return key.contains("=");
            }
        }
        return false;
    }
    
    public AttributedString optionDescription(final String key) {
        return this.optsDesc.get(key).isEmpty() ? new AttributedString("") : this.optsDesc.get(key).get(0);
    }
}
