# 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/modelevaluationslice_model_explanation'
require 'google/vertexai/property/modelevaluationslice_model_explanation_mean_attributions'
require 'google/vertexai/property/modelevaluationslice_slice'
require 'google/vertexai/property/modelevaluationslice_slice_slice_spec'
require 'google/vertexai/property/modelevaluationslice_slice_slice_spec_configs'

# A provider to manage Vertex AI resources.
class VertexAIModelEvaluationSlice < GcpResourceBase
  name 'google_vertex_ai_model_evaluation_slice'
  desc 'ModelEvaluationSlice'
  supports platform: 'gcp'

  attr_reader :params
  attr_reader :create_time
  attr_reader :model_explanation
  attr_reader :name
  attr_reader :metrics
  attr_reader :slice
  attr_reader :metrics_schema_uri

  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
    @create_time = @fetched['createTime']
    @model_explanation = GoogleInSpec::VertexAI::Property::ModelEvaluationSliceModelExplanation.new(@fetched['modelExplanation'], to_s)
    @name = @fetched['name']
    @metrics = @fetched['metrics']
    @slice = GoogleInSpec::VertexAI::Property::ModelEvaluationSliceSlice.new(@fetched['slice'], to_s)
    @metrics_schema_uri = @fetched['metricsSchemaUri']
  end

  def exists?
    !@fetched.nil?
  end

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

  private

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

  def resource_base_url
    '{{name}}'
  end
end
