# 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/cluster_cluster_config'
require 'google/bigtableadmin/property/cluster_cluster_config_cluster_autoscaling_config'
require 'google/bigtableadmin/property/cluster_cluster_config_cluster_autoscaling_config_autoscaling_limits'
require 'google/bigtableadmin/property/cluster_cluster_config_cluster_autoscaling_config_autoscaling_targets'
require 'google/bigtableadmin/property/cluster_encryption_config'

# A provider to manage bigtableadmin resources.
class BigtableadminCluster < GcpResourceBase
  name 'google_bigtableadmin_cluster'
  desc 'Cluster'
  supports platform: 'gcp'

  attr_reader :params
  attr_reader :name
  attr_reader :location
  attr_reader :state
  attr_reader :serve_nodes
  attr_reader :cluster_config
  attr_reader :default_storage_type
  attr_reader :encryption_config

  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']
    @location = @fetched['location']
    @state = @fetched['state']
    @serve_nodes = @fetched['serveNodes']
    @cluster_config = GoogleInSpec::Bigtableadmin::Property::ClusterClusterConfig.new(@fetched['clusterConfig'], to_s)
    @default_storage_type = @fetched['defaultStorageType']
    @encryption_config = GoogleInSpec::Bigtableadmin::Property::ClusterEncryptionConfig.new(@fetched['encryptionConfig'], to_s)
  end

  def exists?
    !@fetched.nil?
  end

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

  private

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

  def resource_base_url
    '{{name}}'
  end
end
