# frozen_string_literal: false

# ----------------------------------------------------------------------------
#
#     ***     AUTO GENERATED CODE    ***    Type: MMv1     ***
#
# ----------------------------------------------------------------------------
#
#     This file is automatically generated by Magic Modules and manual
#     changes will be clobbered when the file is regenerated.
#
#     Please read more about how to change this file in README.md and
#     CONTRIBUTING.md located at the root of this package.
#
# ----------------------------------------------------------------------------
require 'gcp_backend'
class ComputeInterconnectAttachments < GcpResourceBase
  name 'google_compute_interconnect_attachments'
  desc 'InterconnectAttachment plural resource'
  supports platform: 'gcp'

  attr_reader :table

  filter_table_config = FilterTable.create

  filter_table_config.add(:kinds, field: :kind)
  filter_table_config.add(:descriptions, field: :description)
  filter_table_config.add(:self_links, field: :self_link)
  filter_table_config.add(:self_link_with_ids, field: :self_link_with_id)
  filter_table_config.add(:ids, field: :id)
  filter_table_config.add(:creation_timestamps, field: :creation_timestamp)
  filter_table_config.add(:names, field: :name)
  filter_table_config.add(:interconnects, field: :interconnect)
  filter_table_config.add(:routers, field: :router)
  filter_table_config.add(:regions, field: :region)
  filter_table_config.add(:google_reference_ids, field: :google_reference_id)
  filter_table_config.add(:mtus, field: :mtu)
  filter_table_config.add(:private_interconnect_infos, field: :private_interconnect_info)
  filter_table_config.add(:operational_statuses, field: :operational_status)
  filter_table_config.add(:cloud_router_ip_addresses, field: :cloud_router_ip_address)
  filter_table_config.add(:customer_router_ip_addresses, field: :customer_router_ip_address)
  filter_table_config.add(:types, field: :type)
  filter_table_config.add(:pairing_keys, field: :pairing_key)
  filter_table_config.add(:admin_enableds, field: :admin_enabled)
  filter_table_config.add(:vlan_tag8021qs, field: :vlan_tag8021q)
  filter_table_config.add(:edge_availability_domains, field: :edge_availability_domain)
  filter_table_config.add(:candidate_subnets, field: :candidate_subnets)
  filter_table_config.add(:bandwidths, field: :bandwidth)
  filter_table_config.add(:partner_metadata, field: :partner_metadata)
  filter_table_config.add(:labels, field: :labels)
  filter_table_config.add(:label_fingerprints, field: :label_fingerprint)
  filter_table_config.add(:states, field: :state)
  filter_table_config.add(:partner_asns, field: :partner_asn)
  filter_table_config.add(:encryptions, field: :encryption)
  filter_table_config.add(:ipsec_internal_addresses, field: :ipsec_internal_addresses)
  filter_table_config.add(:dataplane_versions, field: :dataplane_version)
  filter_table_config.add(:satisfies_pzs, field: :satisfies_pzs)
  filter_table_config.add(:stack_types, field: :stack_type)
  filter_table_config.add(:cloud_router_ipv6_addresses, field: :cloud_router_ipv6_address)
  filter_table_config.add(:customer_router_ipv6_addresses, field: :customer_router_ipv6_address)
  filter_table_config.add(:candidate_ipv6_subnets, field: :candidate_ipv6_subnets)
  filter_table_config.add(:cloud_router_ipv6_interface_ids, field: :cloud_router_ipv6_interface_id)
  filter_table_config.add(:customer_router_ipv6_interface_ids, field: :customer_router_ipv6_interface_id)
  filter_table_config.add(:subnet_lengths, field: :subnet_length)
  filter_table_config.add(:remote_services, field: :remote_service)
  filter_table_config.add(:configuration_constraints, field: :configuration_constraints)
  filter_table_config.add(:multicast_enableds, field: :multicast_enabled)

  filter_table_config.connect(self, :table)

  def initialize(params = {})
    super(params.merge({ use_http_transport: true }))
    @params = params
    @table = fetch_wrapped_resource('items')
  end

  def fetch_wrapped_resource(wrap_path)
    # fetch_resource returns an array of responses (to handle pagination)
    result = @connection.fetch_all(product_url, resource_base_url, @params, 'Get')
    return if result.nil?

    # Conversion of string -> object hash to symbol -> object hash that InSpec needs
    converted = []
    result.each do |response|
      next if response.nil? || !response.key?(wrap_path)
      response[wrap_path].each do |hash|
        hash_with_symbols = {}
        hash.each_key do |key|
          name, value = transform(key, hash)
          hash_with_symbols[name] = value
        end
        converted.push(hash_with_symbols)
      end
    end

    converted
  end

  def transform(key, value)
    return transformers[key].call(value) if transformers.key?(key)

    [key.to_sym, value]
  end

  def transformers
    {
      'kind' => ->(obj) { [:kind, obj['kind']] },
      'description' => ->(obj) { [:description, obj['description']] },
      'selfLink' => ->(obj) { [:self_link, obj['selfLink']] },
      'selfLinkWithId' => ->(obj) { [:self_link_with_id, obj['selfLinkWithId']] },
      'id' => ->(obj) { [:id, obj['id']] },
      'creationTimestamp' => ->(obj) { [:creation_timestamp, obj['creationTimestamp']] },
      'name' => ->(obj) { [:name, obj['name']] },
      'interconnect' => ->(obj) { [:interconnect, obj['interconnect']] },
      'router' => ->(obj) { [:router, obj['router']] },
      'region' => ->(obj) { [:region, obj['region']] },
      'googleReferenceId' => ->(obj) { [:google_reference_id, obj['googleReferenceId']] },
      'mtu' => ->(obj) { [:mtu, obj['mtu']] },
      'privateInterconnectInfo' => ->(obj) { [:private_interconnect_info, GoogleInSpec::Compute::Property::InterconnectAttachmentPrivateInterconnectInfo.new(obj['privateInterconnectInfo'], to_s)] },
      'operationalStatus' => ->(obj) { [:operational_status, obj['operationalStatus']] },
      'cloudRouterIpAddress' => ->(obj) { [:cloud_router_ip_address, obj['cloudRouterIpAddress']] },
      'customerRouterIpAddress' => ->(obj) { [:customer_router_ip_address, obj['customerRouterIpAddress']] },
      'type' => ->(obj) { [:type, obj['type']] },
      'pairingKey' => ->(obj) { [:pairing_key, obj['pairingKey']] },
      'adminEnabled' => ->(obj) { [:admin_enabled, obj['adminEnabled']] },
      'vlanTag8021q' => ->(obj) { [:vlan_tag8021q, obj['vlanTag8021q']] },
      'edgeAvailabilityDomain' => ->(obj) { [:edge_availability_domain, obj['edgeAvailabilityDomain']] },
      'candidateSubnets' => ->(obj) { [:candidate_subnets, obj['candidateSubnets']] },
      'bandwidth' => ->(obj) { [:bandwidth, obj['bandwidth']] },
      'partnerMetadata' => ->(obj) { [:partner_metadata, GoogleInSpec::Compute::Property::InterconnectAttachmentPartnerMetadata.new(obj['partnerMetadata'], to_s)] },
      'labels' => ->(obj) { [:labels, GoogleInSpec::Compute::Property::InterconnectAttachmentLabels.new(obj['labels'], to_s)] },
      'labelFingerprint' => ->(obj) { [:label_fingerprint, obj['labelFingerprint']] },
      'state' => ->(obj) { [:state, obj['state']] },
      'partnerAsn' => ->(obj) { [:partner_asn, obj['partnerAsn']] },
      'encryption' => ->(obj) { [:encryption, obj['encryption']] },
      'ipsecInternalAddresses' => ->(obj) { [:ipsec_internal_addresses, obj['ipsecInternalAddresses']] },
      'dataplaneVersion' => ->(obj) { [:dataplane_version, obj['dataplaneVersion']] },
      'satisfiesPzs' => ->(obj) { [:satisfies_pzs, obj['satisfiesPzs']] },
      'stackType' => ->(obj) { [:stack_type, obj['stackType']] },
      'cloudRouterIpv6Address' => ->(obj) { [:cloud_router_ipv6_address, obj['cloudRouterIpv6Address']] },
      'customerRouterIpv6Address' => ->(obj) { [:customer_router_ipv6_address, obj['customerRouterIpv6Address']] },
      'candidateIpv6Subnets' => ->(obj) { [:candidate_ipv6_subnets, obj['candidateIpv6Subnets']] },
      'cloudRouterIpv6InterfaceId' => ->(obj) { [:cloud_router_ipv6_interface_id, obj['cloudRouterIpv6InterfaceId']] },
      'customerRouterIpv6InterfaceId' => ->(obj) { [:customer_router_ipv6_interface_id, obj['customerRouterIpv6InterfaceId']] },
      'subnetLength' => ->(obj) { [:subnet_length, obj['subnetLength']] },
      'remoteService' => ->(obj) { [:remote_service, obj['remoteService']] },
      'configurationConstraints' => ->(obj) { [:configuration_constraints, GoogleInSpec::Compute::Property::InterconnectAttachmentConfigurationConstraints.new(obj['configurationConstraints'], to_s)] },
      'multicastEnabled' => ->(obj) { [:multicast_enabled, obj['multicastEnabled']] },
    }
  end

  private

  def product_url(_ = nil)
    'https://compute.googleapis.com/compute/v1/'
  end

  def resource_base_url
    'projects/{{project}}/regions/{{region}}/interconnectAttachments'
  end
end
