require "devops-client/output/base"

module Output
  class Chef < Base

    def table
      headers, rows, title = nil, nil, nil
      case options[:current_command]
      when :bootstrap_templates
        headers, rows = create_bootstrap_templates
        title = "output.title.chef.bootstrap_templates"
      when :tags_list
        headers, rows = create_tags_list
        title = "output.title.chef.tags_list"
      end
      create_table(headers, rows, I18n.t(title))
    end

    def csv
      headers, rows = nil, nil
      case options[:current_command]
      when :bootstrap_templates
        headers, rows = create_bootstrap_templates
      when :tags_list
        headers, rows = create_tags_list
      end

      create_csv(headers, rows)
    end

  private
    def create_bootstrap_templates
      abort I18n.t("output.not_found.chef.bootstrap_template") if @data.empty?
      headers_and_rows_for_array(@data, "name")
    end

    def create_tags_list
      abort I18n.t("output.not_found.chef.tags_list") if @data.empty?
      headers_and_rows_for_array(@data, "name")
    end

  end
end

