# 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'
require 'google/compute/property/serviceattachment_connected_endpoints'
require 'google/compute/property/serviceattachment_consumer_accept_lists'
require 'google/compute/property/serviceattachment_psc_service_attachment_id'

# A provider to manage Compute Engine resources.
class ComputeServiceAttachment < GcpResourceBase
  name 'google_compute_service_attachment'
  desc 'ServiceAttachment'
  supports platform: 'gcp'

  attr_reader :params
  attr_reader :kind
  attr_reader :id
  attr_reader :creation_timestamp
  attr_reader :name
  attr_reader :description
  attr_reader :self_link
  attr_reader :region
  attr_reader :producer_forwarding_rule
  attr_reader :target_service
  attr_reader :connection_preference
  attr_reader :connected_endpoints
  attr_reader :nat_subnets
  attr_reader :enable_proxy_protocol
  attr_reader :consumer_reject_lists
  attr_reader :consumer_accept_lists
  attr_reader :psc_service_attachment_id
  attr_reader :fingerprint
  attr_reader :domain_names
  attr_reader :reconcile_connections

  def initialize(params)
    super(params.merge({ use_http_transport: true }))
    @params = params
    @fetched = @connection.fetch(product_url(params[:beta]), resource_base_url, params, 'Get')
    parse unless @fetched.nil?
  end

  def parse
    @kind = @fetched['kind']
    @id = @fetched['id']
    @creation_timestamp = @fetched['creationTimestamp']
    @name = @fetched['name']
    @description = @fetched['description']
    @self_link = @fetched['selfLink']
    @region = @fetched['region']
    @producer_forwarding_rule = @fetched['producerForwardingRule']
    @target_service = @fetched['targetService']
    @connection_preference = @fetched['connectionPreference']
    @connected_endpoints = GoogleInSpec::Compute::Property::ServiceAttachmentConnectedEndpointsArray.parse(@fetched['connectedEndpoints'], to_s)
    @nat_subnets = @fetched['natSubnets']
    @enable_proxy_protocol = @fetched['enableProxyProtocol']
    @consumer_reject_lists = @fetched['consumerRejectLists']
    @consumer_accept_lists = GoogleInSpec::Compute::Property::ServiceAttachmentConsumerAcceptListsArray.parse(@fetched['consumerAcceptLists'], to_s)
    @psc_service_attachment_id = GoogleInSpec::Compute::Property::ServiceAttachmentPscServiceAttachmentId.new(@fetched['pscServiceAttachmentId'], to_s)
    @fingerprint = @fetched['fingerprint']
    @domain_names = @fetched['domainNames']
    @reconcile_connections = @fetched['reconcileConnections']
  end

  def exists?
    !@fetched.nil?
  end

  def to_s
    "ServiceAttachment #{@params[:service_attachment]}"
  end

  private

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

  def resource_base_url
    'projects/{{project}}/regions/{{region}}/serviceAttachments/{{service_attachment}}'
  end
end
