# 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/hyperparametertuningjob_labels'

# A provider to manage Vertex AI resources.
class VertexAIHyperparameterTuningJob < GcpResourceBase
  name 'google_vertex_ai_hyperparameter_tuning_job'
  desc 'HyperparameterTuningJob'
  supports platform: 'gcp'

  attr_reader :params
  attr_reader :study_spec
  attr_reader :trials
  attr_reader :state
  attr_reader :max_failed_trial_count
  attr_reader :encryption_spec
  attr_reader :error
  attr_reader :end_time
  attr_reader :update_time
  attr_reader :start_time
  attr_reader :labels
  attr_reader :create_time
  attr_reader :parallel_trial_count
  attr_reader :trial_job_spec
  attr_reader :max_trial_count
  attr_reader :display_name
  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
    @study_spec = @fetched['studySpec']
    @trials = @fetched['trials']
    @state = @fetched['state']
    @max_failed_trial_count = @fetched['maxFailedTrialCount']
    @encryption_spec = @fetched['encryptionSpec']
    @error = @fetched['error']
    @end_time = @fetched['endTime']
    @update_time = @fetched['updateTime']
    @start_time = @fetched['startTime']
    @labels = GoogleInSpec::VertexAI::Property::HyperparameterTuningJobLabels.new(@fetched['labels'], to_s)
    @create_time = @fetched['createTime']
    @parallel_trial_count = @fetched['parallelTrialCount']
    @trial_job_spec = @fetched['trialJobSpec']
    @max_trial_count = @fetched['maxTrialCount']
    @display_name = @fetched['displayName']
    @name = @fetched['name']
  end

  def exists?
    !@fetched.nil?
  end

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

  private

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

  def resource_base_url
    '{{name}}'
  end
end
