# 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/reservation_aggregate_reservation'
require 'google/compute/property/reservation_aggregate_reservation_in_use_resources'
require 'google/compute/property/reservation_aggregate_reservation_reserved_resources'
require 'google/compute/property/reservation_delete_after_duration'
require 'google/compute/property/reservation_resource_policies'
require 'google/compute/property/reservation_resource_status'
require 'google/compute/property/reservation_resource_status_specific_sku_allocation'
require 'google/compute/property/reservation_share_settings'
require 'google/compute/property/reservation_share_settings_folder_map'
require 'google/compute/property/reservation_share_settings_project_map'
require 'google/compute/property/reservation_specific_reservation'
require 'google/compute/property/reservation_specific_reservation_instance_properties'
require 'google/compute/property/reservation_specific_reservation_instance_properties_guest_accelerators'
require 'google/compute/property/reservation_specific_reservation_instance_properties_local_ssds'

# A provider to manage Compute Engine resources.
class ComputeReservation < GcpResourceBase
  name 'google_compute_reservation'
  desc 'Reservation'
  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 :zone
  attr_reader :description
  attr_reader :name
  attr_reader :specific_reservation
  attr_reader :aggregate_reservation
  attr_reader :commitment
  attr_reader :specific_reservation_required
  attr_reader :status
  attr_reader :share_settings
  attr_reader :satisfies_pzs
  attr_reader :resource_policies
  attr_reader :resource_status
  attr_reader :delete_at_time
  attr_reader :delete_after_duration

  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']
    @zone = @fetched['zone']
    @description = @fetched['description']
    @name = @fetched['name']
    @specific_reservation = GoogleInSpec::Compute::Property::ReservationSpecificReservation.new(@fetched['specificReservation'], to_s)
    @aggregate_reservation = GoogleInSpec::Compute::Property::ReservationAggregateReservation.new(@fetched['aggregateReservation'], to_s)
    @commitment = @fetched['commitment']
    @specific_reservation_required = @fetched['specificReservationRequired']
    @status = @fetched['status']
    @share_settings = GoogleInSpec::Compute::Property::ReservationShareSettings.new(@fetched['shareSettings'], to_s)
    @satisfies_pzs = @fetched['satisfiesPzs']
    @resource_policies = GoogleInSpec::Compute::Property::ReservationResourcePolicies.new(@fetched['resourcePolicies'], to_s)
    @resource_status = GoogleInSpec::Compute::Property::ReservationResourceStatus.new(@fetched['resourceStatus'], to_s)
    @delete_at_time = @fetched['deleteAtTime']
    @delete_after_duration = GoogleInSpec::Compute::Property::ReservationDeleteAfterDuration.new(@fetched['deleteAfterDuration'], to_s)
  end

  def exists?
    !@fetched.nil?
  end

  def to_s
    "Reservation #{@params[:reservation]}"
  end

  private

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

  def resource_base_url
    'projects/{{project}}/zones/{{zone}}/reservations/{{name}}'
  end
end
