# 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/pubsub/property/integer'
require 'google/pubsub/property/string'
require 'google/pubsub/property/subscription_push_config'
require 'google/pubsub/property/topic_name'
require 'puppet'

Puppet::Type.newtype(:gpubsub_subscription) do
  @doc = <<-DOC
    A named resource representing the stream of messages from a single, specific topic, to be
    delivered to the subscribing application.
  DOC

  autorequire(:gauth_credential) do
    credential = self[:credential]
    raise "#{ref}: required property 'credential' is missing" if credential.nil?
    [credential]
  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 Subscription.'
  end

  newproperty(:name, parent: Google::Pubsub::Property::String) do
    desc 'Name of the subscription.'
  end

  newproperty(:topic, parent: Google::Pubsub::Property::TopicNameRef) do
    desc 'A reference to a Topic resource.'
  end

  newproperty(:push_config, parent: Google::Pubsub::Property::SubscriptionPushConfig) do
    desc <<-DOC
      If push delivery is used with this subscription, this field is used to configure it. An empty
      pushConfig signifies that the subscriber will pull and ack messages using API methods.
    DOC
  end

  newproperty(:ack_deadline_seconds, parent: Google::Pubsub::Property::Integer) do
    desc <<-DOC
      This value is the maximum time after a subscriber receives a message before the subscriber
      should acknowledge the message. After message delivery but before the ack deadline expires
      and before the message is acknowledged, it is an outstanding message and will not be
      delivered again during that time (on a best-effort basis). For pull subscriptions, this value
      is used as the initial value for the ack deadline. To override this value for a given
      message, call subscriptions.modifyAckDeadline with the corresponding ackId if using pull. The
      minimum custom deadline you can specify is 10 seconds. The maximum custom deadline you can
      specify is 600 seconds (10 minutes). If this parameter is 0, a default value of 10 seconds is
      used. For push delivery, this value is also used to set the request timeout for the call to
      the push endpoint. If the subscriber never acknowledges the message, the Pub/Sub system will
      eventually redeliver the message.
    DOC
  end
end
