# 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/studiestrial_final_measurement'
require 'google/vertexai/property/studiestrial_final_measurement_metrics'
require 'google/vertexai/property/studiestrial_measurements'
require 'google/vertexai/property/studiestrial_parameters'
require 'google/vertexai/property/studiestrial_web_access_uris'

# A provider to manage Vertex AI resources.
class VertexAIStudiesTrial < GcpResourceBase
  name 'google_vertex_ai_studies_trial'
  desc 'StudiesTrial'
  supports platform: 'gcp'

  attr_reader :params
  attr_reader :measurements
  attr_reader :start_time
  attr_reader :end_time
  attr_reader :parameters
  attr_reader :name
  attr_reader :infeasible_reason
  attr_reader :final_measurement
  attr_reader :client_id
  attr_reader :custom_job
  attr_reader :state
  attr_reader :web_access_uris
  attr_reader :id

  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
    @measurements = GoogleInSpec::VertexAI::Property::StudiesTrialMeasurementsArray.parse(@fetched['measurements'], to_s)
    @start_time = @fetched['startTime']
    @end_time = @fetched['endTime']
    @parameters = GoogleInSpec::VertexAI::Property::StudiesTrialParametersArray.parse(@fetched['parameters'], to_s)
    @name = @fetched['name']
    @infeasible_reason = @fetched['infeasibleReason']
    @final_measurement = GoogleInSpec::VertexAI::Property::StudiesTrialFinalMeasurement.new(@fetched['finalMeasurement'], to_s)
    @client_id = @fetched['clientId']
    @custom_job = @fetched['customJob']
    @state = @fetched['state']
    @web_access_uris = GoogleInSpec::VertexAI::Property::StudiesTrialWebAccessUris.new(@fetched['webAccessUris'], to_s)
    @id = @fetched['id']
  end

  def exists?
    !@fetched.nil?
  end

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

  private

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

  def resource_base_url
    '{{name}}'
  end
end
