# 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/compute/property/regionurlmap_default_custom_error_response_policy'
require 'google/compute/property/regionurlmap_default_custom_error_response_policy_error_response_rules'
require 'google/compute/property/regionurlmap_default_route_action'
require 'google/compute/property/regionurlmap_default_route_action_cors_policy'
require 'google/compute/property/regionurlmap_default_route_action_fault_injection_policy'
require 'google/compute/property/regionurlmap_default_route_action_fault_injection_policy_abort'
require 'google/compute/property/regionurlmap_default_route_action_fault_injection_policy_delay'
require 'google/compute/property/regionurlmap_default_route_action_fault_injection_policy_delay_fixed_delay'
require 'google/compute/property/regionurlmap_default_route_action_max_stream_duration'
require 'google/compute/property/regionurlmap_default_route_action_request_mirror_policy'
require 'google/compute/property/regionurlmap_default_route_action_retry_policy'
require 'google/compute/property/regionurlmap_default_route_action_retry_policy_per_try_timeout'
require 'google/compute/property/regionurlmap_default_route_action_timeout'
require 'google/compute/property/regionurlmap_default_route_action_url_rewrite'
require 'google/compute/property/regionurlmap_default_route_action_weighted_backend_services'
require 'google/compute/property/regionurlmap_default_url_redirect'
require 'google/compute/property/regionurlmap_header_action'
require 'google/compute/property/regionurlmap_header_action_request_headers_to_add'
require 'google/compute/property/regionurlmap_header_action_response_headers_to_add'
require 'google/compute/property/regionurlmap_host_rules'
require 'google/compute/property/regionurlmap_path_matchers'
require 'google/compute/property/regionurlmap_tests'

# A provider to manage Compute Engine resources.
class ComputeRegionUrlMap < GcpResourceBase
  name 'google_compute_region_url_map'
  desc 'RegionUrlMap'
  supports platform: 'gcp'

  attr_reader :params
  attr_reader :kind
  attr_reader :id
  attr_reader :creation_timestamp
  attr_reader :name
  attr_reader :description
  attr_reader :self_link
  attr_reader :host_rules
  attr_reader :path_matchers
  attr_reader :tests
  attr_reader :default_service
  attr_reader :default_route_action
  attr_reader :default_url_redirect
  attr_reader :header_action
  attr_reader :default_custom_error_response_policy
  attr_reader :fingerprint
  attr_reader :region

  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
    @kind = @fetched['kind']
    @id = @fetched['id']
    @creation_timestamp = @fetched['creationTimestamp']
    @name = @fetched['name']
    @description = @fetched['description']
    @self_link = @fetched['selfLink']
    @host_rules = GoogleInSpec::Compute::Property::RegionUrlMapHostRulesArray.parse(@fetched['hostRules'], to_s)
    @path_matchers = GoogleInSpec::Compute::Property::RegionUrlMapPathMatchersArray.parse(@fetched['pathMatchers'], to_s)
    @tests = GoogleInSpec::Compute::Property::RegionUrlMapTestsArray.parse(@fetched['tests'], to_s)
    @default_service = @fetched['defaultService']
    @default_route_action = GoogleInSpec::Compute::Property::RegionUrlMapDefaultRouteAction.new(@fetched['defaultRouteAction'], to_s)
    @default_url_redirect = GoogleInSpec::Compute::Property::RegionUrlMapDefaultUrlRedirect.new(@fetched['defaultUrlRedirect'], to_s)
    @header_action = GoogleInSpec::Compute::Property::RegionUrlMapHeaderAction.new(@fetched['headerAction'], to_s)
    @default_custom_error_response_policy = GoogleInSpec::Compute::Property::RegionUrlMapDefaultCustomErrorResponsePolicy.new(@fetched['defaultCustomErrorResponsePolicy'], to_s)
    @fingerprint = @fetched['fingerprint']
    @region = @fetched['region']
  end

  def exists?
    !@fetched.nil?
  end

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

  private

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

  def resource_base_url
    'projects/{{project}}/regions/{{region}}/urlMaps/{{name}}'
  end
end
