# This file was generated by `inspec init resource <%= resource_name %>`
# using the "--template plural" option. It represents a "plural" (FilterTable-based)
# InSpec resource.

# Plural resources query multiple resources of the same type in bulk. For details of the
# differences between singular and plural resources, please see:
# https://www.chef.io/blog/understanding-singular-and-plural-inspec-resources

# Plural resources rely on the FilterTable facility to handle data lookup and querying.
# For details on Filtertable and how to use it effectively within your resource, please see
# https://github.com/inspec/inspec/blob/main/dev-docs/filtertable-usage.md
# Consider that page required reading for authoring plural resources.

# Uncomment the below lines to add gems and files required by the resource
# require "inspec/utils/filter"
# require_relative ""

# Include FilterTable support
require "inspec/utils/filter"

module Inspec::Resources
  # Most custom InSpec resource inherit from a dynamic class, InSpec.resource(1).
  # If you wish to inherit from a core resource, you need to follow special instructions -
  # see https://www.chef.io/blog/extending-inspec-resources-core-resource-inheritance
  class <%= class_name %> < Inspec.resource(1)
    # Every resource requires an internal name.
    name "<%= resource_name %>"

    # Restrict to only run on the below platforms (if none were given,
    # all OS's and cloud API's supported)
    supports platform: "<%= supports_platform %>"

    desc "<%= description %>"

    example <<~EXAMPLE
      describe <%= resource_name %>.where{ shoe_size > 10 } do
        its("count") { should cmp 0 }
      end
    EXAMPLE

    # Resource initialization. Add any arguments you want to pass to the contructor here.
    # Anything you pass here will be passed to the "describe" call:
    # describe <%= resource_name %>(YOUR_PARAMETERS_HERE) do
    #   its("shoe_size") { should cmp 10 }
    # end
    def initialize
      # Initialize required path/params/configs
    end

    # Define the FilterTable. This will define many extra methods on your resource, including
    # where(), count(), and a property for every column.
    table = FilterTable.create
    table.register_column(:names, field: :name, style: :simple)
      .register_column(:shoe_sizes, field: :shoe_size)
      .install_filter_methods_on_resource(self, :fetch_data)

    # Plural resources do not generally define a resource_id.

    # Define how you want your resource to appear in test reports. Commonly, this is just the resource name for plural resources.
    def to_s
      "<%= resource_name %>"
    end

    # Do whatever you need to do to fetch the underlying data.
    # Return it as an array of hashes.
    def fetch_data
      [
        { name: "Bob",   shoe_size: 9 },
        { name: "Alice", shoe_size: 8 },
      ]
    end
  end
end
