# 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/dataprocmetastore/property/service_encryption_config'
require 'google/dataprocmetastore/property/service_hive_metastore_config'
require 'google/dataprocmetastore/property/service_hive_metastore_config_auxiliary_versions'
require 'google/dataprocmetastore/property/service_hive_metastore_config_config_overrides'
require 'google/dataprocmetastore/property/service_hive_metastore_config_kerberos_config'
require 'google/dataprocmetastore/property/service_hive_metastore_config_kerberos_config_keytab'
require 'google/dataprocmetastore/property/service_labels'
require 'google/dataprocmetastore/property/service_maintenance_window'
require 'google/dataprocmetastore/property/service_metadata_integration'
require 'google/dataprocmetastore/property/service_metadata_integration_data_catalog_config'
require 'google/dataprocmetastore/property/service_metadata_integration_dataplex_config'
require 'google/dataprocmetastore/property/service_metadata_integration_dataplex_config_lake_resources'
require 'google/dataprocmetastore/property/service_metadata_management_activity'
require 'google/dataprocmetastore/property/service_metadata_management_activity_metadata_exports'
require 'google/dataprocmetastore/property/service_metadata_management_activity_restores'
require 'google/dataprocmetastore/property/service_network_config'
require 'google/dataprocmetastore/property/service_network_config_consumers'
require 'google/dataprocmetastore/property/service_scaling_config'
require 'google/dataprocmetastore/property/service_scaling_config_autoscaling_config'
require 'google/dataprocmetastore/property/service_scaling_config_autoscaling_config_limit_config'
require 'google/dataprocmetastore/property/service_scheduled_backup'
require 'google/dataprocmetastore/property/service_scheduled_backup_latest_backup'
require 'google/dataprocmetastore/property/service_telemetry_config'

# A provider to manage Dataproc metastore resources.
class DataprocMetastoreService < GcpResourceBase
  name 'google_dataproc_metastore_service'
  desc 'Service'
  supports platform: 'gcp'

  attr_reader :params
  attr_reader :hive_metastore_config
  attr_reader :name
  attr_reader :create_time
  attr_reader :update_time
  attr_reader :labels
  attr_reader :network
  attr_reader :endpoint_uri
  attr_reader :port
  attr_reader :state
  attr_reader :state_message
  attr_reader :artifact_gcs_uri
  attr_reader :tier
  attr_reader :metadata_integration
  attr_reader :maintenance_window
  attr_reader :uid
  attr_reader :metadata_management_activity
  attr_reader :release_channel
  attr_reader :encryption_config
  attr_reader :network_config
  attr_reader :database_type
  attr_reader :telemetry_config
  attr_reader :scaling_config
  attr_reader :scheduled_backup
  attr_reader :deletion_protection

  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
    @hive_metastore_config = GoogleInSpec::DataprocMetastore::Property::ServiceHiveMetastoreConfig.new(@fetched['hiveMetastoreConfig'], to_s)
    @name = @fetched['name']
    @create_time = @fetched['createTime']
    @update_time = @fetched['updateTime']
    @labels = GoogleInSpec::DataprocMetastore::Property::ServiceLabels.new(@fetched['labels'], to_s)
    @network = @fetched['network']
    @endpoint_uri = @fetched['endpointUri']
    @port = @fetched['port']
    @state = @fetched['state']
    @state_message = @fetched['stateMessage']
    @artifact_gcs_uri = @fetched['artifactGcsUri']
    @tier = @fetched['tier']
    @metadata_integration = GoogleInSpec::DataprocMetastore::Property::ServiceMetadataIntegration.new(@fetched['metadataIntegration'], to_s)
    @maintenance_window = GoogleInSpec::DataprocMetastore::Property::ServiceMaintenanceWindow.new(@fetched['maintenanceWindow'], to_s)
    @uid = @fetched['uid']
    @metadata_management_activity = GoogleInSpec::DataprocMetastore::Property::ServiceMetadataManagementActivity.new(@fetched['metadataManagementActivity'], to_s)
    @release_channel = @fetched['releaseChannel']
    @encryption_config = GoogleInSpec::DataprocMetastore::Property::ServiceEncryptionConfig.new(@fetched['encryptionConfig'], to_s)
    @network_config = GoogleInSpec::DataprocMetastore::Property::ServiceNetworkConfig.new(@fetched['networkConfig'], to_s)
    @database_type = @fetched['databaseType']
    @telemetry_config = GoogleInSpec::DataprocMetastore::Property::ServiceTelemetryConfig.new(@fetched['telemetryConfig'], to_s)
    @scaling_config = GoogleInSpec::DataprocMetastore::Property::ServiceScalingConfig.new(@fetched['scalingConfig'], to_s)
    @scheduled_backup = GoogleInSpec::DataprocMetastore::Property::ServiceScheduledBackup.new(@fetched['scheduledBackup'], to_s)
    @deletion_protection = @fetched['deletionProtection']
  end

  def exists?
    !@fetched.nil?
  end

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

  private

  def product_url(_ = nil)
    'https://metastore.googleapis.com/v1beta/'
  end

  def resource_base_url
    '{{name}}'
  end
end
