# frozen_string_literal: true

# The code was auto-generated by {this script}[https://github.com/cucumber/messages/blob/main/codegen/codegen.rb]
module Cucumber
  module Messages
    ##
    # Represents the PickleTable message in Cucumber's {message protocol}[https://github.com/cucumber/messages].
    ##
    ##
    class PickleTable < Message
      attr_reader :argument_index

      attr_reader :rows

      def initialize(
        argument_index: nil,
        rows: []
      )
        @argument_index = argument_index
        @rows = rows
        super()
      end

      ##
      # Returns a new PickleTable from the given hash.
      # If the hash keys are camelCased, they are properly assigned to the
      # corresponding snake_cased attributes.
      #
      #   Cucumber::Messages::PickleTable.from_h(some_hash) # => #<Cucumber::Messages::PickleTable:0x... ...>
      ##
      def self.from_h(hash)
        return nil if hash.nil?

        new(
          argument_index: hash[:argumentIndex],
          rows: hash[:rows]&.map { |item| PickleTableRow.from_h(item) }
        )
      end
    end
  end
end
