# 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/servicebackup_service_revision'
require 'google/dataprocmetastore/property/servicebackup_service_revision_encryption_config'
require 'google/dataprocmetastore/property/servicebackup_service_revision_hive_metastore_config'
require 'google/dataprocmetastore/property/servicebackup_service_revision_hive_metastore_config_auxiliary_versions'
require 'google/dataprocmetastore/property/servicebackup_service_revision_hive_metastore_config_config_overrides'
require 'google/dataprocmetastore/property/servicebackup_service_revision_hive_metastore_config_kerberos_config'
require 'google/dataprocmetastore/property/servicebackup_service_revision_hive_metastore_config_kerberos_config_keytab'
require 'google/dataprocmetastore/property/servicebackup_service_revision_labels'
require 'google/dataprocmetastore/property/servicebackup_service_revision_maintenance_window'
require 'google/dataprocmetastore/property/servicebackup_service_revision_metadata_integration'
require 'google/dataprocmetastore/property/servicebackup_service_revision_metadata_integration_data_catalog_config'
require 'google/dataprocmetastore/property/servicebackup_service_revision_metadata_integration_dataplex_config'
require 'google/dataprocmetastore/property/servicebackup_service_revision_metadata_integration_dataplex_config_lake_resources'
require 'google/dataprocmetastore/property/servicebackup_service_revision_metadata_management_activity'
require 'google/dataprocmetastore/property/servicebackup_service_revision_metadata_management_activity_metadata_exports'
require 'google/dataprocmetastore/property/servicebackup_service_revision_metadata_management_activity_restores'
require 'google/dataprocmetastore/property/servicebackup_service_revision_network_config'
require 'google/dataprocmetastore/property/servicebackup_service_revision_network_config_consumers'
require 'google/dataprocmetastore/property/servicebackup_service_revision_scaling_config'
require 'google/dataprocmetastore/property/servicebackup_service_revision_scaling_config_autoscaling_config'
require 'google/dataprocmetastore/property/servicebackup_service_revision_scaling_config_autoscaling_config_limit_config'
require 'google/dataprocmetastore/property/servicebackup_service_revision_scheduled_backup'
require 'google/dataprocmetastore/property/servicebackup_service_revision_scheduled_backup_latest_backup'
require 'google/dataprocmetastore/property/servicebackup_service_revision_telemetry_config'

# A provider to manage Dataproc metastore resources.
class DataprocMetastoreServiceBackup < GcpResourceBase
  name 'google_dataproc_metastore_service_backup'
  desc 'ServiceBackup'
  supports platform: 'gcp'

  attr_reader :params
  attr_reader :name
  attr_reader :create_time
  attr_reader :end_time
  attr_reader :state
  attr_reader :service_revision
  attr_reader :description
  attr_reader :restoring_services

  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']
    @create_time = @fetched['createTime']
    @end_time = @fetched['endTime']
    @state = @fetched['state']
    @service_revision = GoogleInSpec::DataprocMetastore::Property::ServiceBackupServiceRevision.new(@fetched['serviceRevision'], to_s)
    @description = @fetched['description']
    @restoring_services = @fetched['restoringServices']
  end

  def exists?
    !@fetched.nil?
  end

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

  private

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

  def resource_base_url
    '{{name}}'
  end
end
