# 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/dataproc/property/workflowtemplate_encryption_config'
require 'google/dataproc/property/workflowtemplate_jobs'
require 'google/dataproc/property/workflowtemplate_labels'
require 'google/dataproc/property/workflowtemplate_parameters'
require 'google/dataproc/property/workflowtemplate_placement'
require 'google/dataproc/property/workflowtemplate_placement_cluster_selector'
require 'google/dataproc/property/workflowtemplate_placement_cluster_selector_cluster_labels'
require 'google/dataproc/property/workflowtemplate_placement_managed_cluster'
require 'google/dataproc/property/workflowtemplate_placement_managed_cluster_config'
require 'google/dataproc/property/workflowtemplate_placement_managed_cluster_config_autoscaling_config'
require 'google/dataproc/property/workflowtemplate_placement_managed_cluster_config_auxiliary_node_groups'
require 'google/dataproc/property/workflowtemplate_placement_managed_cluster_config_dataproc_metric_config'
require 'google/dataproc/property/workflowtemplate_placement_managed_cluster_config_dataproc_metric_config_metrics'
require 'google/dataproc/property/workflowtemplate_placement_managed_cluster_config_encryption_config'
require 'google/dataproc/property/workflowtemplate_placement_managed_cluster_config_endpoint_config'
require 'google/dataproc/property/workflowtemplate_placement_managed_cluster_config_endpoint_config_http_ports'
require 'google/dataproc/property/workflowtemplate_placement_managed_cluster_config_gce_cluster_config'
require 'google/dataproc/property/workflowtemplate_placement_managed_cluster_config_gce_cluster_config_confidential_instance_config'
require 'google/dataproc/property/workflowtemplate_placement_managed_cluster_config_gce_cluster_config_metadata'
require 'google/dataproc/property/workflowtemplate_placement_managed_cluster_config_gce_cluster_config_node_group_affinity'
require 'google/dataproc/property/workflowtemplate_placement_managed_cluster_config_gce_cluster_config_reservation_affinity'
require 'google/dataproc/property/workflowtemplate_placement_managed_cluster_config_gce_cluster_config_shielded_instance_config'
require 'google/dataproc/property/workflowtemplate_gke_cluster_config'
require 'google/dataproc/property/workflowtemplate_gke_cluster_config_namespaced_gke_deployment_target'
require 'google/dataproc/property/workflowtemplate_gke_cluster_config_node_pool_target'
require 'google/dataproc/property/workflowtemplate_placement_managed_cluster_config_initialization_actions'
require 'google/dataproc/property/workflowtemplate_placement_managed_cluster_config_lifecycle_config'
require 'google/dataproc/property/workflowtemplate_master_config'
require 'google/dataproc/property/workflowtemplate_master_config_accelerators'
require 'google/dataproc/property/workflowtemplate_master_config_disk_config'
require 'google/dataproc/property/workflowtemplate_master_config_instance_flexibility_policy'
require 'google/dataproc/property/workflowtemplate_master_config_instance_flexibility_policy_instance_selection_list'
require 'google/dataproc/property/workflowtemplate_master_config_instance_flexibility_policy_instance_selection_results'
require 'google/dataproc/property/workflowtemplate_master_config_instance_references'
require 'google/dataproc/property/workflowtemplate_master_config_managed_group_config'
require 'google/dataproc/property/workflowtemplate_master_config_startup_config'
require 'google/dataproc/property/workflowtemplate_placement_managed_cluster_config_metastore_config'
require 'google/dataproc/property/workflowtemplate_secondary_worker_config'
require 'google/dataproc/property/workflowtemplate_secondary_worker_config_accelerators'
require 'google/dataproc/property/workflowtemplate_secondary_worker_config_disk_config'
require 'google/dataproc/property/workflowtemplate_secondary_worker_config_instance_flexibility_policy'
require 'google/dataproc/property/workflowtemplate_secondary_worker_config_instance_flexibility_policy_instance_selection_list'
require 'google/dataproc/property/workflowtemplate_secondary_worker_config_instance_flexibility_policy_instance_selection_results'
require 'google/dataproc/property/workflowtemplate_secondary_worker_config_instance_references'
require 'google/dataproc/property/workflowtemplate_secondary_worker_config_managed_group_config'
require 'google/dataproc/property/workflowtemplate_secondary_worker_config_startup_config'
require 'google/dataproc/property/workflowtemplate_placement_managed_cluster_config_security_config'
require 'google/dataproc/property/workflowtemplate_security_config_identity_config'
require 'google/dataproc/property/workflowtemplate_security_config_identity_config_user_service_account_mapping'
require 'google/dataproc/property/workflowtemplate_placement_managed_cluster_config_security_config_kerberos_config'
require 'google/dataproc/property/workflowtemplate_placement_managed_cluster_config_software_config'
require 'google/dataproc/property/workflowtemplate_placement_managed_cluster_config_software_config_properties'
require 'google/dataproc/property/workflowtemplate_worker_config'
require 'google/dataproc/property/workflowtemplate_worker_config_accelerators'
require 'google/dataproc/property/workflowtemplate_worker_config_disk_config'
require 'google/dataproc/property/workflowtemplate_worker_config_instance_flexibility_policy'
require 'google/dataproc/property/workflowtemplate_worker_config_instance_flexibility_policy_instance_selection_list'
require 'google/dataproc/property/workflowtemplate_worker_config_instance_flexibility_policy_instance_selection_results'
require 'google/dataproc/property/workflowtemplate_worker_config_instance_references'
require 'google/dataproc/property/workflowtemplate_worker_config_managed_group_config'
require 'google/dataproc/property/workflowtemplate_worker_config_startup_config'
require 'google/dataproc/property/workflowtemplate_placement_managed_cluster_labels'

# A provider to manage Dataproc resources.
class DataprocWorkflowTemplate < GcpResourceBase
  name 'google_dataproc_workflow_template'
  desc 'WorkflowTemplate'
  supports platform: 'gcp'

  attr_reader :params
  attr_reader :id
  attr_reader :name
  attr_reader :version
  attr_reader :create_time
  attr_reader :update_time
  attr_reader :labels
  attr_reader :placement
  attr_reader :jobs
  attr_reader :parameters
  attr_reader :dag_timeout
  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
    @id = @fetched['id']
    @name = @fetched['name']
    @version = @fetched['version']
    @create_time = @fetched['createTime']
    @update_time = @fetched['updateTime']
    @labels = GoogleInSpec::Dataproc::Property::WorkflowTemplateLabels.new(@fetched['labels'], to_s)
    @placement = GoogleInSpec::Dataproc::Property::WorkflowTemplatePlacement.new(@fetched['placement'], to_s)
    @jobs = GoogleInSpec::Dataproc::Property::WorkflowTemplateJobsArray.parse(@fetched['jobs'], to_s)
    @parameters = GoogleInSpec::Dataproc::Property::WorkflowTemplateParametersArray.parse(@fetched['parameters'], to_s)
    @dag_timeout = @fetched['dagTimeout']
    @encryption_config = GoogleInSpec::Dataproc::Property::WorkflowTemplateEncryptionConfig.new(@fetched['encryptionConfig'], to_s)
  end

  def exists?
    !@fetched.nil?
  end

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

  private

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

  def resource_base_url
    '{{name}}'
  end
end
