# 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/bigtableadmin/property/instanceappprofile_data_boost_isolation_read_only'
require 'google/bigtableadmin/property/instanceappprofile_multi_cluster_routing_use_any'
require 'google/bigtableadmin/property/instanceappprofile_single_cluster_routing'
require 'google/bigtableadmin/property/instanceappprofile_standard_isolation'

# A provider to manage bigtableadmin resources.
class BigtableadminInstanceAppProfile < GcpResourceBase
  name 'google_bigtableadmin_instance_app_profile'
  desc 'InstanceAppProfile'
  supports platform: 'gcp'

  attr_reader :params
  attr_reader :name
  attr_reader :etag
  attr_reader :description
  attr_reader :multi_cluster_routing_use_any
  attr_reader :single_cluster_routing
  attr_reader :priority
  attr_reader :standard_isolation
  attr_reader :data_boost_isolation_read_only

  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
    @name = @fetched['name']
    @etag = @fetched['etag']
    @description = @fetched['description']
    @multi_cluster_routing_use_any = GoogleInSpec::Bigtableadmin::Property::InstanceAppProfileMultiClusterRoutingUseAny.new(@fetched['multiClusterRoutingUseAny'], to_s)
    @single_cluster_routing = GoogleInSpec::Bigtableadmin::Property::InstanceAppProfileSingleClusterRouting.new(@fetched['singleClusterRouting'], to_s)
    @priority = @fetched['priority']
    @standard_isolation = GoogleInSpec::Bigtableadmin::Property::InstanceAppProfileStandardIsolation.new(@fetched['standardIsolation'], to_s)
    @data_boost_isolation_read_only = GoogleInSpec::Bigtableadmin::Property::InstanceAppProfileDataBoostIsolationReadOnly.new(@fetched['dataBoostIsolationReadOnly'], to_s)
  end

  def exists?
    !@fetched.nil?
  end

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

  private

  def product_url(_ = nil)
    'https://bigtableadmin.googleapis.com/v2/'
  end

  def resource_base_url
    '{{name}}'
  end
end
