# 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 Group message in Cucumber's {message protocol}[https://github.com/cucumber/messages].
    ##
    ##
    class Group < Message
      ##
      # The nested capture groups of an argument.
      # Absent if the group has no nested capture groups.
      ##
      attr_reader :children

      attr_reader :start

      attr_reader :value

      def initialize(
        children: nil,
        start: nil,
        value: nil
      )
        @children = children
        @start = start
        @value = value
        super()
      end

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

        new(
          children: hash[:children]&.map { |item| Group.from_h(item) },
          start: hash[:start],
          value: hash[:value]
        )
      end
    end
  end
end
