<commit_before>
#
# subnet_route_table
# subnet_route
# subnet_route_table_assoc
#

SparkleFormation.dynamic(:subnet_route_table) do |_tier, _az, _config = {}|
  _config = {} if _config.nil?
  _prefix = "#{_tier}_#{_az}"
  _name = "#{_prefix}_table".to_sym

  _state = {
    tier: _tier,
    label: join!("-", _az, "-", _tier)
  }

  nested_configs = {}
  nested_dynamics = %w(
    routes
    state
    tags
  )

  nested_dynamics.each do |key|
    nested_configs[key.to_sym] = _config.delete(key.to_sym) || {}
  end

  nested_configs[:routes].each do |key, hash|
    hash[:route_table_id] = ref!(_name)
    route_name = "#{_prefix}_#{key}_route".to_sym
    dynamic! :subnet_route, route_name, hash
  end

  resources.set!(_name) do
    set_state!(_state.merge(nested_configs[:state]))
    registry! :default_config, :config, vpc_id: ref!(:vpc_id)
    registry! :apply_config, :config, _config
    registry! :apply_config, :tags, nested_configs[:tags]

    properties do
      state!(:config).each do |key, value|
        set!(key, value)
      end
      tags registry!(:context_tags)
    end
  end
end

SparkleFormation.dynamic(:subnet_route) do |_name, _config = {}|
  _config = {} if _config.nil?

  resources.set!(_name) do
    registry! :default_config, :config,
      route_table_id: nil,
      network_interface_id: nil,
      vpc_peering_connection_id: nil,
      instance_id: nil,
      gateway_id: nil,
      destination_cidr_block: nil

    registry! :apply_config, :config,
      _config

    properties do
      state!(:config).each do |k,v|
        set!(k,v)
      end
    end
  end
end

SparkleFormation.dynamic(:subnet) do |_tier, _az, _config = {}|
  _config = {} if _config.nil?
  _state = {
    tier: _tier,
    label: join!("-", _az, "-", _tier)
  }

  _name         = "#{_tier}_#{_az}_table".to_sym
  _param_name   = "vpc_cidr_#{_az}_#{_tier}".to_sym
  _subnet_name  = "#{_tier}_#{_az}_subnet".to_sym
  _table_name   = "#{_tier}_#{_az}_table".to_sym
  _assoc_name   = "#{_tier}_#{_az}_assoc".to_sym

  nested_configs = {}
  nested_dynamics = %w(<commit_msg>Resources require types..duhhh..<commit_after>
#
# subnet_route_table
# subnet_route
# subnet_route_table_assoc
#

SparkleFormation.dynamic(:subnet_route_table) do |_tier, _az, _config = {}|
  _config = {} if _config.nil?
  _prefix = "#{_tier}_#{_az}"
  _name = "#{_prefix}_table".to_sym

  _state = {
    tier: _tier,
    label: join!("-", _az, "-", _tier)
  }

  nested_configs = {}
  nested_dynamics = %w(
    routes
    state
    tags
  )

  nested_dynamics.each do |key|
    nested_configs[key.to_sym] = _config.delete(key.to_sym) || {}
  end

  nested_configs[:routes].each do |key, hash|
    hash[:route_table_id] = ref!(_name)
    route_name = "#{_prefix}_#{key}_route".to_sym
    dynamic! :subnet_route, route_name, hash
  end

  resources.set!(_name) do
    set_state!(_state.merge(nested_configs[:state]))

    registry! :default_config, :config, vpc_id: ref!(:vpc_id)
    registry! :apply_config, :config, _config
    registry! :apply_config, :tags, nested_configs[:tags]

    type "AWS::EC2::RouteTable"

    properties do
      state!(:config).each do |key, value|
        set!(key, value)
      end
      tags registry!(:context_tags)
    end
  end
end

SparkleFormation.dynamic(:subnet_route) do |_name, _config = {}|
  _config = {} if _config.nil?

  resources.set!(_name) do
    registry! :default_config, :config,
      route_table_id: nil,
      network_interface_id: nil,
      vpc_peering_connection_id: nil,
      instance_id: nil,
      gateway_id: nil,
      destination_cidr_block: nil

    registry! :apply_config, :config,
      _config

    type "AWS::EC2::Route"

    properties do
      state!(:config).each do |k,v|
        set!(k,v)
      end
    end
  end
end

SparkleFormation.dynamic(:subnet) do |_tier, _az, _config = {}|
  _config = {} if _config.nil?
  _state = {
    tier: _tier,
    label: join!("-", _az, "-", _tier)
  }

  _name         = "#{_tier}_#{_az}_table".to_sym
  _param_name   = "vpc_cidr_#{_az}_#{_tier}".to_sym
  _subnet_name  = "#{_tier}_#{_az}_subnet".to_sym
  _table_name   = "#{_tier}_#{_az}_table".to_sym
  _assoc_name   = "#{_tier}_#{_az}_assoc".to_sym

  nested_configs = {}
  nested_dynamics = %w(
{'fraction_non_alphanumeric': 0.1463299504366297, 'fraction_numerical': 0.0004720320981826764, 'mean_word_length': 3.4145833333333333, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7242208', 'n_tokens_mistral': 1666, 'n_tokens_neox': 1637, 'n_words': 293}