# 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/nasjobsnastrialdetail_search_trial'
require 'google/vertexai/property/nasjobsnastrialdetail_search_trial_final_measurement'
require 'google/vertexai/property/nasjobsnastrialdetail_search_trial_final_measurement_metrics'
require 'google/vertexai/property/nasjobsnastrialdetail_train_trial'
require 'google/vertexai/property/nasjobsnastrialdetail_train_trial_final_measurement'
require 'google/vertexai/property/nasjobsnastrialdetail_train_trial_final_measurement_metrics'

# A provider to manage Vertex AI resources.
class VertexAINasJobsNasTrialDetail < GcpResourceBase
  name 'google_vertex_ai_nas_jobs_nas_trial_detail'
  desc 'NasJobsNasTrialDetail'
  supports platform: 'gcp'

  attr_reader :params
  attr_reader :parameters
  attr_reader :name
  attr_reader :search_trial
  attr_reader :train_trial

  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
    @parameters = @fetched['parameters']
    @name = @fetched['name']
    @search_trial = GoogleInSpec::VertexAI::Property::NasJobsNasTrialDetailSearchTrial.new(@fetched['searchTrial'], to_s)
    @train_trial = GoogleInSpec::VertexAI::Property::NasJobsNasTrialDetailTrainTrial.new(@fetched['trainTrial'], to_s)
  end

  def exists?
    !@fetched.nil?
  end

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

  private

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

  def resource_base_url
    '{{name}}'
  end
end
