package cli.tag;

import cli.Subcommand;

public class TagCommands extends Subcommand {

    final private CustomTagsCliAdapter customTagsCliAdapter;


    public TagCommands(CustomTagsCliAdapter customTagsCliAdapter) {
        this.customTagsCliAdapter = customTagsCliAdapter;
        commands.put("add", this::addCustomTag);
        commands.put("get", this::getTags);
    }

    @Override
    public String getSubcommand() {
        return "tag";
    }

    @Override
    public String getUsage() {
        return "Usage: " + System.lineSeparator() +
                getSubcommand() + " add tagName tagRegexExpression";
    }

    private String addCustomTag(String[] args) {
        customTagsCliAdapter.addCustomTagMatcher(args[1], args[2]);
        return "Added the new Tag matcher";
    }

    private String getTags(String[] args) {
        var firstLine = "All available Tags:" + System.lineSeparator();
        return firstLine + String.join(System.lineSeparator(), customTagsCliAdapter.getAllTagNames());
    }
}
