# 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/machineimage_instance_properties'
require 'google/compute/property/machineimage_instance_properties_advanced_machine_features'
require 'google/compute/property/machineimage_instance_properties_confidential_instance_config'
require 'google/compute/property/machineimage_instance_properties_disks'
require 'google/compute/property/machineimage_instance_properties_guest_accelerators'
require 'google/compute/property/machineimage_instance_properties_labels'
require 'google/compute/property/machineimage_instance_properties_metadata'
require 'google/compute/property/machineimage_instance_properties_metadata_items'
require 'google/compute/property/machineimage_instance_properties_network_interfaces'
require 'google/compute/property/machineimage_instance_properties_network_performance_config'
require 'google/compute/property/machineimage_instance_properties_reservation_affinity'
require 'google/compute/property/machineimage_instance_properties_resource_manager_tags'
require 'google/compute/property/machineimage_instance_properties_scheduling'
require 'google/compute/property/machineimage_instance_properties_scheduling_local_ssd_recovery_timeout'
require 'google/compute/property/machineimage_instance_properties_scheduling_node_affinities'
require 'google/compute/property/machineimage_instance_properties_service_accounts'
require 'google/compute/property/machineimage_instance_properties_shielded_instance_config'
require 'google/compute/property/machineimage_instance_properties_tags'
require 'google/compute/property/machineimage_machine_image_encryption_key'
require 'google/compute/property/machineimage_saved_disks'
require 'google/compute/property/machineimage_source_disk_encryption_keys'
require 'google/compute/property/machineimage_source_instance_properties'
require 'google/compute/property/machineimage_source_instance_properties_disks'
require 'google/compute/property/machineimage_source_instance_properties_guest_accelerators'
require 'google/compute/property/machineimage_source_instance_properties_labels'
require 'google/compute/property/machineimage_source_instance_properties_metadata'
require 'google/compute/property/machineimage_source_instance_properties_metadata_items'
require 'google/compute/property/machineimage_source_instance_properties_network_interfaces'
require 'google/compute/property/machineimage_source_instance_properties_scheduling'
require 'google/compute/property/machineimage_source_instance_properties_scheduling_local_ssd_recovery_timeout'
require 'google/compute/property/machineimage_source_instance_properties_scheduling_node_affinities'
require 'google/compute/property/machineimage_source_instance_properties_service_accounts'
require 'google/compute/property/machineimage_source_instance_properties_tags'

# A provider to manage Compute Engine resources.
class ComputeMachineImage < GcpResourceBase
  name 'google_compute_machine_image'
  desc 'MachineImage'
  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 :source_instance
  attr_reader :status
  attr_reader :source_instance_properties
  attr_reader :instance_properties
  attr_reader :saved_disks
  attr_reader :storage_locations
  attr_reader :machine_image_encryption_key
  attr_reader :guest_flush
  attr_reader :source_disk_encryption_keys
  attr_reader :total_storage_bytes
  attr_reader :satisfies_pzs

  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']
    @source_instance = @fetched['sourceInstance']
    @status = @fetched['status']
    @source_instance_properties = GoogleInSpec::Compute::Property::MachineImageSourceInstanceProperties.new(@fetched['sourceInstanceProperties'], to_s)
    @instance_properties = GoogleInSpec::Compute::Property::MachineImageInstanceProperties.new(@fetched['instanceProperties'], to_s)
    @saved_disks = GoogleInSpec::Compute::Property::MachineImageSavedDisksArray.parse(@fetched['savedDisks'], to_s)
    @storage_locations = @fetched['storageLocations']
    @machine_image_encryption_key = GoogleInSpec::Compute::Property::MachineImageMachineImageEncryptionKey.new(@fetched['machineImageEncryptionKey'], to_s)
    @guest_flush = @fetched['guestFlush']
    @source_disk_encryption_keys = GoogleInSpec::Compute::Property::MachineImageSourceDiskEncryptionKeysArray.parse(@fetched['sourceDiskEncryptionKeys'], to_s)
    @total_storage_bytes = @fetched['totalStorageBytes']
    @satisfies_pzs = @fetched['satisfiesPzs']
  end

  def exists?
    !@fetched.nil?
  end

  def to_s
    "MachineImage #{@params[:machineImage]}"
  end

  private

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

  def resource_base_url
    'projects/{{project}}/global/machineImages/{{name}}'
  end
end
