# 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/bigtableadmin/property/clusterbackup_encryption_info'
require 'google/bigtableadmin/property/clusterbackup_encryption_info_encryption_status'

# A provider to manage bigtableadmin resources.
class BigtableadminClusterBackup < GcpResourceBase
  name 'google_bigtableadmin_cluster_backup'
  desc 'ClusterBackup'
  supports platform: 'gcp'

  attr_reader :params
  attr_reader :name
  attr_reader :source_table
  attr_reader :source_backup
  attr_reader :expire_time
  attr_reader :start_time
  attr_reader :end_time
  attr_reader :size_bytes
  attr_reader :state
  attr_reader :encryption_info

  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']
    @source_table = @fetched['sourceTable']
    @source_backup = @fetched['sourceBackup']
    @expire_time = @fetched['expireTime']
    @start_time = @fetched['startTime']
    @end_time = @fetched['endTime']
    @size_bytes = @fetched['sizeBytes']
    @state = @fetched['state']
    @encryption_info = GoogleInSpec::Bigtableadmin::Property::ClusterBackupEncryptionInfo.new(@fetched['encryptionInfo'], to_s)
  end

  def exists?
    !@fetched.nil?
  end

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

  private

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

  def resource_base_url
    '{{name}}'
  end
end
