# 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/run/property/service_annotations'
require 'google/run/property/service_binary_authorization'
require 'google/run/property/service_conditions'
require 'google/run/property/service_labels'
require 'google/run/property/service_scaling'
require 'google/run/property/service_template'
require 'google/run/property/service_template_annotations'
require 'google/run/property/service_template_containers'
require 'google/run/property/service_template_labels'
require 'google/run/property/service_template_node_selector'
require 'google/run/property/service_template_scaling'
require 'google/run/property/service_template_volumes'
require 'google/run/property/service_template_vpc_access'
require 'google/run/property/service_template_vpc_access_network_interfaces'
require 'google/run/property/service_terminal_condition'
require 'google/run/property/service_traffic'
require 'google/run/property/service_traffic_statuses'

# A provider to manage run resources.
class RunService < GcpResourceBase
  name 'google_run_service'
  desc 'Service'
  supports platform: 'gcp'

  attr_reader :params
  attr_reader :name
  attr_reader :description
  attr_reader :uid
  attr_reader :generation
  attr_reader :labels
  attr_reader :annotations
  attr_reader :create_time
  attr_reader :update_time
  attr_reader :delete_time
  attr_reader :expire_time
  attr_reader :creator
  attr_reader :last_modifier
  attr_reader :client
  attr_reader :client_version
  attr_reader :ingress
  attr_reader :launch_stage
  attr_reader :binary_authorization
  attr_reader :template
  attr_reader :traffic
  attr_reader :scaling
  attr_reader :default_uri_disabled
  attr_reader :custom_audiences
  attr_reader :observed_generation
  attr_reader :terminal_condition
  attr_reader :conditions
  attr_reader :latest_ready_revision
  attr_reader :latest_created_revision
  attr_reader :traffic_statuses
  attr_reader :uri
  attr_reader :satisfies_pzs
  attr_reader :reconciling
  attr_reader :etag

  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']
    @description = @fetched['description']
    @uid = @fetched['uid']
    @generation = @fetched['generation']
    @labels = GoogleInSpec::Run::Property::ServiceLabels.new(@fetched['labels'], to_s)
    @annotations = GoogleInSpec::Run::Property::ServiceAnnotations.new(@fetched['annotations'], to_s)
    @create_time = @fetched['createTime']
    @update_time = @fetched['updateTime']
    @delete_time = @fetched['deleteTime']
    @expire_time = @fetched['expireTime']
    @creator = @fetched['creator']
    @last_modifier = @fetched['lastModifier']
    @client = @fetched['client']
    @client_version = @fetched['clientVersion']
    @ingress = @fetched['ingress']
    @launch_stage = @fetched['launchStage']
    @binary_authorization = GoogleInSpec::Run::Property::ServiceBinaryAuthorization.new(@fetched['binaryAuthorization'], to_s)
    @template = GoogleInSpec::Run::Property::ServiceTemplate.new(@fetched['template'], to_s)
    @traffic = GoogleInSpec::Run::Property::ServiceTrafficArray.parse(@fetched['traffic'], to_s)
    @scaling = GoogleInSpec::Run::Property::ServiceScaling.new(@fetched['scaling'], to_s)
    @default_uri_disabled = @fetched['defaultUriDisabled']
    @custom_audiences = @fetched['customAudiences']
    @observed_generation = @fetched['observedGeneration']
    @terminal_condition = GoogleInSpec::Run::Property::ServiceTerminalCondition.new(@fetched['terminalCondition'], to_s)
    @conditions = GoogleInSpec::Run::Property::ServiceConditionsArray.parse(@fetched['conditions'], to_s)
    @latest_ready_revision = @fetched['latestReadyRevision']
    @latest_created_revision = @fetched['latestCreatedRevision']
    @traffic_statuses = GoogleInSpec::Run::Property::ServiceTrafficStatusesArray.parse(@fetched['trafficStatuses'], to_s)
    @uri = @fetched['uri']
    @satisfies_pzs = @fetched['satisfiesPzs']
    @reconciling = @fetched['reconciling']
    @etag = @fetched['etag']
  end

  def exists?
    !@fetched.nil?
  end

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

  private

  def product_url(_ = nil)
    'https://run.googleapis.com/v2/'
  end

  def resource_base_url
    '{{name}}'
  end
end
