# 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/resourcepolicy_group_placement_policy'
require 'google/compute/property/resourcepolicy_instance_schedule_policy'
require 'google/compute/property/resourcepolicy_instance_schedule_policy_vm_start_schedule'
require 'google/compute/property/resourcepolicy_instance_schedule_policy_vm_stop_schedule'
require 'google/compute/property/resourcepolicy_resource_status'
require 'google/compute/property/resourcepolicy_resource_status_instance_schedule_policy'
require 'google/compute/property/resourcepolicy_snapshot_schedule_policy'
require 'google/compute/property/resourcepolicy_snapshot_schedule_policy_retention_policy'
require 'google/compute/property/resourcepolicy_snapshot_schedule_policy_schedule'
require 'google/compute/property/resourcepolicy_snapshot_schedule_policy_schedule_daily_schedule'
require 'google/compute/property/resourcepolicy_snapshot_schedule_policy_schedule_hourly_schedule'
require 'google/compute/property/resourcepolicy_snapshot_schedule_policy_schedule_weekly_schedule'
require 'google/compute/property/resourcepolicy_snapshot_schedule_policy_schedule_weekly_schedule_day_of_weeks'
require 'google/compute/property/resourcepolicy_snapshot_schedule_policy_snapshot_properties'
require 'google/compute/property/resourcepolicy_snapshot_schedule_policy_snapshot_properties_labels'
require 'google/compute/property/resourcepolicy_vm_maintenance_policy'
require 'google/compute/property/resourcepolicy_vm_maintenance_policy_concurrency_control_group'
require 'google/compute/property/resourcepolicy_vm_maintenance_policy_maintenance_window'
require 'google/compute/property/resourcepolicy_vm_maintenance_policy_maintenance_window_daily_maintenance_window'

# A provider to manage Compute Engine resources.
class ComputeResourcePolicy < GcpResourceBase
  name 'google_compute_resource_policy'
  desc 'ResourcePolicy'
  supports platform: 'gcp'

  attr_reader :params
  attr_reader :kind
  attr_reader :id
  attr_reader :creation_timestamp
  attr_reader :self_link
  attr_reader :self_link_with_id
  attr_reader :region
  attr_reader :description
  attr_reader :name
  attr_reader :vm_maintenance_policy
  attr_reader :snapshot_schedule_policy
  attr_reader :group_placement_policy
  attr_reader :instance_schedule_policy
  attr_reader :status
  attr_reader :resource_status

  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']
    @self_link = @fetched['selfLink']
    @self_link_with_id = @fetched['selfLinkWithId']
    @region = @fetched['region']
    @description = @fetched['description']
    @name = @fetched['name']
    @vm_maintenance_policy = GoogleInSpec::Compute::Property::ResourcePolicyVmMaintenancePolicy.new(@fetched['vmMaintenancePolicy'], to_s)
    @snapshot_schedule_policy = GoogleInSpec::Compute::Property::ResourcePolicySnapshotSchedulePolicy.new(@fetched['snapshotSchedulePolicy'], to_s)
    @group_placement_policy = GoogleInSpec::Compute::Property::ResourcePolicyGroupPlacementPolicy.new(@fetched['groupPlacementPolicy'], to_s)
    @instance_schedule_policy = GoogleInSpec::Compute::Property::ResourcePolicyInstanceSchedulePolicy.new(@fetched['instanceSchedulePolicy'], to_s)
    @status = @fetched['status']
    @resource_status = GoogleInSpec::Compute::Property::ResourcePolicyResourceStatus.new(@fetched['resourceStatus'], to_s)
  end

  def exists?
    !@fetched.nil?
  end

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

  private

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

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