# 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/interconnect_circuit_infos'
require 'google/compute/property/interconnect_expected_outages'

# A provider to manage Compute Engine resources.
class ComputeInterconnect < GcpResourceBase
  name 'google_compute_interconnect'
  desc 'Interconnect'
  supports platform: 'gcp'

  attr_reader :params
  attr_reader :admin_enabled
  attr_reader :creation_timestamp
  attr_reader :description
  attr_reader :location
  attr_reader :id
  attr_reader :name
  attr_reader :noc_contact_email
  attr_reader :peer_ip_address
  attr_reader :google_ip_address
  attr_reader :client_operation_id
  attr_reader :google_reference_id
  attr_reader :provisioned_link_count
  attr_reader :customer_name
  attr_reader :requested_link_count
  attr_reader :operational_status
  attr_reader :link_type
  attr_reader :interconnect_type
  attr_reader :interconnect_attachments
  attr_reader :expected_outages
  attr_reader :circuit_infos
  attr_reader :satisfies_pzs

  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
    @admin_enabled = @fetched['adminEnabled']
    @creation_timestamp = parse_time_string(@fetched['creationTimestamp'])
    @description = @fetched['description']
    @location = @fetched['location']
    @id = @fetched['id']
    @name = @fetched['name']
    @noc_contact_email = @fetched['nocContactEmail']
    @peer_ip_address = @fetched['peerIpAddress']
    @google_ip_address = @fetched['googleIpAddress']
    @client_operation_id = @fetched['clientOperationId']
    @google_reference_id = @fetched['googleReferenceId']
    @provisioned_link_count = @fetched['provisionedLinkCount']
    @customer_name = @fetched['customerName']
    @requested_link_count = @fetched['requestedLinkCount']
    @operational_status = @fetched['operationalStatus']
    @link_type = @fetched['linkType']
    @interconnect_type = @fetched['interconnectType']
    @interconnect_attachments = @fetched['interconnectAttachments']
    @expected_outages = GoogleInSpec::Compute::Property::InterconnectExpectedOutagesArray.parse(@fetched['expectedOutages'], to_s)
    @circuit_infos = GoogleInSpec::Compute::Property::InterconnectCircuitInfosArray.parse(@fetched['circuitInfos'], to_s)
    @satisfies_pzs = @fetched['satisfiesPzs']
  end

  # Handles parsing RFC3339 time string
  def parse_time_string(time_string)
    time_string ? Time.parse(time_string) : nil
  end

  def exists?
    !@fetched.nil?
  end

  def to_s
    "Interconnect #{@params[:name]}"
  end

  private

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

  def resource_base_url
    'projects/{{project}}/global/interconnects/{{name}}'
  end
end
