package cli.category;

import cli.Subcommand;

public class CategoryCommands extends Subcommand {

	final private CategoryCliAdapter categoryCliAdapter;

	public CategoryCommands(CategoryCliAdapter categoryCliAdapter) {
		this.categoryCliAdapter = categoryCliAdapter;
		commands.put("add", this::addCategory);
		commands.put("get", this::getCategories);
	}

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

	@Override
	public String getUsage() {
		return "Usage:" + System.lineSeparator() + getSubcommand() + " add categoryName" + System.lineSeparator() + getSubcommand() + " get";

	}

	private String addCategory(String[] args) {
		categoryCliAdapter.addCategory(args[1]);
		return "Added the new category";
	}

	private String getCategories(String[] _ignored) {
		return "Available Categories:" + System.lineSeparator() + String.join(System.lineSeparator(),
		                                                                      categoryCliAdapter.getCategories());
	}

}
