# 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/vertexai/property/metadatastore_encryption_spec'
require 'google/vertexai/property/metadatastore_state'

# A provider to manage Vertex AI resources.
class VertexAIMetadataStore < GcpResourceBase
  name 'google_vertex_ai_metadata_store'
  desc 'MetadataStore'
  supports platform: 'gcp'

  attr_reader :params
  attr_reader :description
  attr_reader :create_time
  attr_reader :update_time
  attr_reader :encryption_spec
  attr_reader :state
  attr_reader :name

  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
    @description = @fetched['description']
    @create_time = @fetched['createTime']
    @update_time = @fetched['updateTime']
    @encryption_spec = GoogleInSpec::VertexAI::Property::MetadataStoreEncryptionSpec.new(@fetched['encryptionSpec'], to_s)
    @state = GoogleInSpec::VertexAI::Property::MetadataStoreState.new(@fetched['state'], to_s)
    @name = @fetched['name']
  end

  def exists?
    !@fetched.nil?
  end

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

  private

  def product_url(_ = nil)
    'https://{{region}}-aiplatform.googleapis.com/v1/'
  end

  def resource_base_url
    '{{name}}'
  end
end
