# Copyright 2018 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# ----------------------------------------------------------------------------
#
#     ***     AUTO GENERATED CODE    ***    AUTO GENERATED CODE     ***
#
# ----------------------------------------------------------------------------
#
#     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 'google/compute/property/disk_name'
require 'google/compute/property/integer'
require 'google/compute/property/license_selflink'
require 'google/compute/property/snapshot_snapshot_encryption_key'
require 'google/compute/property/snapshot_source_disk_encryption_key'
require 'google/compute/property/string'
require 'google/compute/property/string_array'
require 'google/compute/property/time'
require 'google/compute/property/zone_name'
require 'google/object_store'
require 'puppet'

Puppet::Type.newtype(:gcompute_snapshot) do
  @doc = <<-DOC
    Represents a Persistent Disk Snapshot resource. Use snapshots to back up data from your
    persistent disks. Snapshots are different from public images and custom images, which are used
    primarily to create instances or configure instance templates. Snapshots are useful for
    periodic backup of the data on your persistent disks. You can create snapshots from persistent
    disks even while they are attached to running instances. Snapshots are incremental, so you can
    create regular snapshots on a persistent disk faster and at a much lower cost than if you
    regularly created a full image of the disk.
  DOC

  autorequire(:gauth_credential) do
    credential = self[:credential]
    raise "#{ref}: required property 'credential' is missing" if credential.nil?
    [credential]
  end

  autorequire(:gcompute_disk) do
    reference = self[:source]
    reference.autorequires unless reference.nil?
  end

  autorequire(:gcompute_zone) do
    reference = self[:zone]
    reference.autorequires unless reference.nil?
  end

  ensurable

  newparam :credential do
    desc <<-DESC
      A gauth_credential name to be used to authenticate with Google Cloud
      Platform.
    DESC
  end

  newparam(:project) do
    desc 'A Google Cloud Platform project to manage.'
  end

  newparam(:name, namevar: true) do
    # TODO(nelsona): Make this description to match the key of the object.
    desc 'The name of the Snapshot.'
  end

  newparam(:source, parent: Google::Compute::Property::DiskNameRef) do
    desc 'A reference to the disk used to create this snapshot.'
  end

  newparam(:zone, parent: Google::Compute::Property::ZoneNameRef) do
    desc 'A reference to the zone where the disk is hosted.'
  end

  newparam(:snapshot_encryption_key,
           parent: Google::Compute::Property::SnapshotSnapshotEncryptionKey) do
    desc <<-DOC
      The customer-supplied encryption key of the snapshot. Required if the source snapshot is
      protected by a customer-supplied encryption key.
    DOC
  end

  newparam(:source_disk_encryption_key,
           parent: Google::Compute::Property::SnapshotSourceDiskEncryptionKey) do
    desc <<-DOC
      The customer-supplied encryption key of the source snapshot. Required if the source snapshot
      is protected by a customer-supplied encryption key.
    DOC
  end

  newproperty(:creation_timestamp, parent: Google::Compute::Property::Time) do
    desc 'Creation timestamp in RFC3339 text format. (output only)'
  end

  newproperty(:id, parent: Google::Compute::Property::Integer) do
    desc 'The unique identifier for the resource. (output only)'
  end

  newproperty(:disk_size_gb, parent: Google::Compute::Property::Integer) do
    desc 'Size of the snapshot, specified in GB. (output only)'
  end

  newproperty(:name, parent: Google::Compute::Property::String) do
    desc <<-DOC
      Name of the resource; provided by the client when the resource is created. The name must be
      1-63 characters long, and comply with RFC1035. Specifically, the name must be 1-63 characters
      long and match the regular expression `[a-z]([-a-z0-9]*[a-z0-9])?` which means the first
      character must be a lowercase letter, and all following characters must be a dash, lowercase
      letter, or digit, except the last character, which cannot be a dash.
    DOC
  end

  newproperty(:description, parent: Google::Compute::Property::String) do
    desc 'An optional description of this resource.'
  end

  newproperty(:storage_bytes, parent: Google::Compute::Property::Integer) do
    desc <<-DOC
      A size of the the storage used by the snapshot. As snapshots share storage, this number is
      expected to change with snapshot creation/deletion. (output only)
    DOC
  end

  newproperty(:licenses, parent: Google::Compute::Property::LicenseSelfLinkRefArray) do
    desc <<-DOC
      A list of public visible licenses that apply to this snapshot. This can be because the
      original image had licenses attached (such as a Windows image). snapshotEncryptionKey nested
      object Encrypts the snapshot using a customer-supplied encryption key.
    DOC
  end

  newproperty(:labels, parent: Google::Compute::Property::StringArray) do
    desc 'Labels to apply to this snapshot.'
  end

  # Returns all properties that a provider can export to other resources
  def exports
    provider.exports
  end
end
