# frozen_string_literal: false

# ----------------------------------------------------------------------------
#
#     ***     AUTO GENERATED CODE    ***    AUTO GENERATED CODE     ***
#
# ----------------------------------------------------------------------------
#
#     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/appengine/property/standardappversion_automatic_scaling'
require 'google/appengine/property/standardappversion_automatic_scaling_standard_scheduler_settings'
require 'google/appengine/property/standardappversion_basic_scaling'
require 'google/appengine/property/standardappversion_manual_scaling'
require 'google/appengine/property/standardappversion_vpc_access_connector'

# A provider to manage App Engine resources.
class AppEngineStandardAppVersion < GcpResourceBase
  name 'google_appengine_standard_app_version'
  desc 'StandardAppVersion'
  supports platform: 'gcp'

  attr_reader :params
  attr_reader :name
  attr_reader :version_id
  attr_reader :runtime
  attr_reader :threadsafe
  attr_reader :vpc_access_connector
  attr_reader :inbound_services
  attr_reader :instance_class
  attr_reader :automatic_scaling
  attr_reader :basic_scaling
  attr_reader :manual_scaling

  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
    @name = @fetched['name']
    @version_id = @fetched['id']
    @runtime = @fetched['runtime']
    @threadsafe = @fetched['threadsafe']
    @vpc_access_connector = GoogleInSpec::AppEngine::Property::StandardAppVersionVPCAccessConnector.new(@fetched['vpcAccessConnector'], to_s)
    @inbound_services = @fetched['inboundServices']
    @instance_class = @fetched['instanceClass']
    @automatic_scaling = GoogleInSpec::AppEngine::Property::StandardAppVersionAutomaticScaling.new(@fetched['automaticScaling'], to_s)
    @basic_scaling = GoogleInSpec::AppEngine::Property::StandardAppVersionBasicScaling.new(@fetched['basicScaling'], to_s)
    @manual_scaling = GoogleInSpec::AppEngine::Property::StandardAppVersionManualScaling.new(@fetched['manualScaling'], to_s)
  end

  def exists?
    !@fetched.nil?
  end

  def to_s
    "StandardAppVersion #{@params[:version_id]}"
  end

  private

  def product_url(_ = nil)
    'https://appengine.googleapis.com/v1/'
  end

  def resource_base_url
    'apps/{{project}}/services/{{service}}/versions/{{version_id}}?view=FULL'
  end
end
