# 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/federation_backend_metastores'
require 'google/dataprocmetastore/property/federation_labels'

# A provider to manage Dataproc metastore resources.
class DataprocMetastoreFederation < GcpResourceBase
  name 'google_dataproc_metastore_federation'
  desc 'Federation'
  supports platform: 'gcp'

  attr_reader :params
  attr_reader :name
  attr_reader :create_time
  attr_reader :update_time
  attr_reader :labels
  attr_reader :version
  attr_reader :backend_metastores
  attr_reader :endpoint_uri
  attr_reader :state
  attr_reader :state_message
  attr_reader :uid

  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']
    @update_time = @fetched['updateTime']
    @labels = GoogleInSpec::DataprocMetastore::Property::FederationLabels.new(@fetched['labels'], to_s)
    @version = @fetched['version']
    @backend_metastores = GoogleInSpec::DataprocMetastore::Property::FederationBackendMetastores.new(@fetched['backendMetastores'], to_s)
    @endpoint_uri = @fetched['endpointUri']
    @state = @fetched['state']
    @state_message = @fetched['stateMessage']
    @uid = @fetched['uid']
  end

  def exists?
    !@fetched.nil?
  end

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

  private

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

  def resource_base_url
    '{{name}}'
  end
end
