# 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/datafusion/property/instance_accelerators'
require 'google/datafusion/property/instance_available_version'
require 'google/datafusion/property/instance_crypto_key_config'
require 'google/datafusion/property/instance_event_publish_config'
require 'google/datafusion/property/instance_labels'
require 'google/datafusion/property/instance_maintenance_policy'
require 'google/datafusion/property/instance_maintenance_policy_maintenance_exclusion_window'
require 'google/datafusion/property/instance_maintenance_policy_maintenance_window'
require 'google/datafusion/property/instance_maintenance_policy_maintenance_window_recurring_time_window'
require 'google/datafusion/property/instance_maintenance_policy_maintenance_window_recurring_time_window_window'
require 'google/datafusion/property/instance_network_config'
require 'google/datafusion/property/instance_network_config_private_service_connect_config'
require 'google/datafusion/property/instance_options'

# A provider to manage Cloud Data Fusion resources.
class DataFusionInstance < GcpResourceBase
  name 'google_data_fusion_instance'
  desc 'Instance'
  supports platform: 'gcp'

  attr_reader :params
  attr_reader :name
  attr_reader :description
  attr_reader :type
  attr_reader :enable_stackdriver_logging
  attr_reader :enable_stackdriver_monitoring
  attr_reader :private_instance
  attr_reader :network_config
  attr_reader :labels
  attr_reader :options
  attr_reader :create_time
  attr_reader :update_time
  attr_reader :state
  attr_reader :state_message
  attr_reader :service_endpoint
  attr_reader :zone
  attr_reader :version
  attr_reader :service_account
  attr_reader :display_name
  attr_reader :available_version
  attr_reader :api_endpoint
  attr_reader :gcs_bucket
  attr_reader :accelerators
  attr_reader :p4_service_account
  attr_reader :tenant_project_id
  attr_reader :dataproc_service_account
  attr_reader :enable_rbac
  attr_reader :crypto_key_config
  attr_reader :disabled_reason
  attr_reader :event_publish_config
  attr_reader :enable_zone_separation
  attr_reader :satisfies_pzs
  attr_reader :workforce_identity_service_endpoint
  attr_reader :patch_revision
  attr_reader :dataplex_data_lineage_integration_enabled
  attr_reader :maintenance_policy

  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']
    @description = @fetched['description']
    @type = @fetched['type']
    @enable_stackdriver_logging = @fetched['enableStackdriverLogging']
    @enable_stackdriver_monitoring = @fetched['enableStackdriverMonitoring']
    @private_instance = @fetched['privateInstance']
    @network_config = GoogleInSpec::DataFusion::Property::InstanceNetworkConfig.new(@fetched['networkConfig'], to_s)
    @labels = GoogleInSpec::DataFusion::Property::InstanceLabels.new(@fetched['labels'], to_s)
    @options = GoogleInSpec::DataFusion::Property::InstanceOptions.new(@fetched['options'], to_s)
    @create_time = @fetched['createTime']
    @update_time = @fetched['updateTime']
    @state = @fetched['state']
    @state_message = @fetched['stateMessage']
    @service_endpoint = @fetched['serviceEndpoint']
    @zone = @fetched['zone']
    @version = @fetched['version']
    @service_account = @fetched['serviceAccount']
    @display_name = @fetched['displayName']
    @available_version = GoogleInSpec::DataFusion::Property::InstanceAvailableVersionArray.parse(@fetched['availableVersion'], to_s)
    @api_endpoint = @fetched['apiEndpoint']
    @gcs_bucket = @fetched['gcsBucket']
    @accelerators = GoogleInSpec::DataFusion::Property::InstanceAcceleratorsArray.parse(@fetched['accelerators'], to_s)
    @p4_service_account = @fetched['p4ServiceAccount']
    @tenant_project_id = @fetched['tenantProjectId']
    @dataproc_service_account = @fetched['dataprocServiceAccount']
    @enable_rbac = @fetched['enableRbac']
    @crypto_key_config = GoogleInSpec::DataFusion::Property::InstanceCryptoKeyConfig.new(@fetched['cryptoKeyConfig'], to_s)
    @disabled_reason = @fetched['disabledReason']
    @event_publish_config = GoogleInSpec::DataFusion::Property::InstanceEventPublishConfig.new(@fetched['eventPublishConfig'], to_s)
    @enable_zone_separation = @fetched['enableZoneSeparation']
    @satisfies_pzs = @fetched['satisfiesPzs']
    @workforce_identity_service_endpoint = @fetched['workforceIdentityServiceEndpoint']
    @patch_revision = @fetched['patchRevision']
    @dataplex_data_lineage_integration_enabled = @fetched['dataplexDataLineageIntegrationEnabled']
    @maintenance_policy = GoogleInSpec::DataFusion::Property::InstanceMaintenancePolicy.new(@fetched['maintenancePolicy'], to_s)
  end

  def exists?
    !@fetched.nil?
  end

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

  private

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

  def resource_base_url
    '{{name}}'
  end
end
