# 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/externalvpngateway_interfaces'

# A provider to manage Compute Engine resources.
class ComputeexternalVpnGateway < GcpResourceBase
  name 'google_compute_external_vpn_gateway'
  desc 'externalVpnGateway'
  supports platform: 'gcp'

  attr_reader :params
  attr_reader :creation_timestamp
  attr_reader :redundancy_type
  attr_reader :interfaces
  attr_reader :labels
  attr_reader :label_fingerprint
  attr_reader :next_page_token
  attr_reader :description
  attr_reader :id
  attr_reader :name

  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
    @creation_timestamp = parse_time_string(@fetched['creationTimestamp'])
    @redundancy_type = @fetched['redundancyType']
    @interfaces = GoogleInSpec::Compute::Property::ExternalVpnGatewayInterfacesArray.parse(@fetched['interfaces'], to_s)
    @labels = @fetched['labels']
    @label_fingerprint = @fetched['labelFingerprint']
    @next_page_token = @fetched['nextPageToken']
    @description = @fetched['description']
    @id = @fetched['id']
    @name = @fetched['name']
  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
    "externalVpnGateway #{@params[:name]}"
  end

  private

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

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