# 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/regionnetworkendpointgroup_annotations'
require 'google/compute/property/regionnetworkendpointgroup_app_engine'
require 'google/compute/property/regionnetworkendpointgroup_cloud_function'
require 'google/compute/property/regionnetworkendpointgroup_cloud_run'
require 'google/compute/property/regionnetworkendpointgroup_psc_data'

# A provider to manage Compute Engine resources.
class ComputeRegionNetworkEndpointGroup < GcpResourceBase
  name 'google_compute_region_network_endpoint_group'
  desc 'RegionNetworkEndpointGroup'
  supports platform: 'gcp'

  attr_reader :params
  attr_reader :kind
  attr_reader :id
  attr_reader :creation_timestamp
  attr_reader :self_link
  attr_reader :name
  attr_reader :description
  attr_reader :network_endpoint_type
  attr_reader :size
  attr_reader :region
  attr_reader :zone
  attr_reader :network
  attr_reader :subnetwork
  attr_reader :default_port
  attr_reader :annotations
  attr_reader :cloud_run
  attr_reader :app_engine
  attr_reader :cloud_function
  attr_reader :psc_target_service
  attr_reader :psc_data

  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']
    @self_link = @fetched['selfLink']
    @name = @fetched['name']
    @description = @fetched['description']
    @network_endpoint_type = @fetched['networkEndpointType']
    @size = @fetched['size']
    @region = @fetched['region']
    @zone = @fetched['zone']
    @network = @fetched['network']
    @subnetwork = @fetched['subnetwork']
    @default_port = @fetched['defaultPort']
    @annotations = GoogleInSpec::Compute::Property::RegionNetworkEndpointGroupAnnotations.new(@fetched['annotations'], to_s)
    @cloud_run = GoogleInSpec::Compute::Property::RegionNetworkEndpointGroupCloudRun.new(@fetched['cloudRun'], to_s)
    @app_engine = GoogleInSpec::Compute::Property::RegionNetworkEndpointGroupAppEngine.new(@fetched['appEngine'], to_s)
    @cloud_function = GoogleInSpec::Compute::Property::RegionNetworkEndpointGroupCloudFunction.new(@fetched['cloudFunction'], to_s)
    @psc_target_service = @fetched['pscTargetService']
    @psc_data = GoogleInSpec::Compute::Property::RegionNetworkEndpointGroupPscData.new(@fetched['pscData'], to_s)
  end

  def exists?
    !@fetched.nil?
  end

  def to_s
    "RegionNetworkEndpointGroup #{@params[:networkEndpointGroup]}"
  end

  private

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

  def resource_base_url
    'projects/{{project}}/regions/{{region}}/networkEndpointGroups/{{network_endpoint_group}}'
  end
end
