=begin
#Docusign eSignature REST API

#The Docusign eSignature REST API provides you with a powerful, convenient, and simple Web services API for interacting with Docusign.

OpenAPI spec version: v2.1
Contact: devcenter@docusign.com
Generated by: https://github.com/swagger-api/swagger-codegen.git

=end

require 'date'

module DocuSign_eSign
  # Contains details about a PowerForm.
  class PowerForm
    # 
    attr_accessor :created_by

    # Indicates the date and time the item was created.
    attr_accessor :created_date_time

    # Specifies the email body of the message sent to the recipient.   Maximum length: 10000 characters. 
    attr_accessor :email_body

    # Specifies the subject of the email that is sent to all recipients.  See [ML:Template Email Subject Merge Fields] for information about adding merge field information to the email subject.
    attr_accessor :email_subject

    # 
    attr_accessor :envelopes

    # Array or errors.
    attr_accessor :error_details

    # 
    attr_accessor :instructions

    # 
    attr_accessor :is_active

    # 
    attr_accessor :last_used

    # 
    attr_accessor :limit_use_interval

    # 
    attr_accessor :limit_use_interval_enabled

    # 
    attr_accessor :limit_use_interval_units

    # 
    attr_accessor :max_use_enabled

    # 
    attr_accessor :name

    # 
    attr_accessor :power_form_id

    # 
    attr_accessor :power_form_url

    # An array of powerform recipients.
    attr_accessor :recipients

    # 
    attr_accessor :sender_name

    # 
    attr_accessor :sender_user_id

    # 
    attr_accessor :signing_mode

    # The unique identifier of the template. If this is not provided, DocuSign will generate a value. 
    attr_accessor :template_id

    # 
    attr_accessor :template_name

    # 
    attr_accessor :times_used

    # 
    attr_accessor :uri

    # 
    attr_accessor :uses_remaining

    # Attribute mapping from ruby-style variable name to JSON key.
    def self.attribute_map
      {
        :'created_by' => :'createdBy',
        :'created_date_time' => :'createdDateTime',
        :'email_body' => :'emailBody',
        :'email_subject' => :'emailSubject',
        :'envelopes' => :'envelopes',
        :'error_details' => :'errorDetails',
        :'instructions' => :'instructions',
        :'is_active' => :'isActive',
        :'last_used' => :'lastUsed',
        :'limit_use_interval' => :'limitUseInterval',
        :'limit_use_interval_enabled' => :'limitUseIntervalEnabled',
        :'limit_use_interval_units' => :'limitUseIntervalUnits',
        :'max_use_enabled' => :'maxUseEnabled',
        :'name' => :'name',
        :'power_form_id' => :'powerFormId',
        :'power_form_url' => :'powerFormUrl',
        :'recipients' => :'recipients',
        :'sender_name' => :'senderName',
        :'sender_user_id' => :'senderUserId',
        :'signing_mode' => :'signingMode',
        :'template_id' => :'templateId',
        :'template_name' => :'templateName',
        :'times_used' => :'timesUsed',
        :'uri' => :'uri',
        :'uses_remaining' => :'usesRemaining'
      }
    end

    # Attribute type mapping.
    def self.swagger_types
      {
        :'created_by' => :'String',
        :'created_date_time' => :'String',
        :'email_body' => :'String',
        :'email_subject' => :'String',
        :'envelopes' => :'Array<Envelope>',
        :'error_details' => :'ErrorDetails',
        :'instructions' => :'String',
        :'is_active' => :'String',
        :'last_used' => :'String',
        :'limit_use_interval' => :'String',
        :'limit_use_interval_enabled' => :'String',
        :'limit_use_interval_units' => :'String',
        :'max_use_enabled' => :'String',
        :'name' => :'String',
        :'power_form_id' => :'String',
        :'power_form_url' => :'String',
        :'recipients' => :'Array<PowerFormRecipient>',
        :'sender_name' => :'String',
        :'sender_user_id' => :'String',
        :'signing_mode' => :'String',
        :'template_id' => :'String',
        :'template_name' => :'String',
        :'times_used' => :'String',
        :'uri' => :'String',
        :'uses_remaining' => :'String'
      }
    end

    # Initializes the object
    # @param [Hash] attributes Model attributes in the form of hash
    def initialize(attributes = {})
      return unless attributes.is_a?(Hash)

      # convert string to symbol for hash key
      attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v }

      if attributes.has_key?(:'createdBy')
        self.created_by = attributes[:'createdBy']
      end

      if attributes.has_key?(:'createdDateTime')
        self.created_date_time = attributes[:'createdDateTime']
      end

      if attributes.has_key?(:'emailBody')
        self.email_body = attributes[:'emailBody']
      end

      if attributes.has_key?(:'emailSubject')
        self.email_subject = attributes[:'emailSubject']
      end

      if attributes.has_key?(:'envelopes')
        if (value = attributes[:'envelopes']).is_a?(Array)
          self.envelopes = value
        end
      end

      if attributes.has_key?(:'errorDetails')
        self.error_details = attributes[:'errorDetails']
      end

      if attributes.has_key?(:'instructions')
        self.instructions = attributes[:'instructions']
      end

      if attributes.has_key?(:'isActive')
        self.is_active = attributes[:'isActive']
      end

      if attributes.has_key?(:'lastUsed')
        self.last_used = attributes[:'lastUsed']
      end

      if attributes.has_key?(:'limitUseInterval')
        self.limit_use_interval = attributes[:'limitUseInterval']
      end

      if attributes.has_key?(:'limitUseIntervalEnabled')
        self.limit_use_interval_enabled = attributes[:'limitUseIntervalEnabled']
      end

      if attributes.has_key?(:'limitUseIntervalUnits')
        self.limit_use_interval_units = attributes[:'limitUseIntervalUnits']
      end

      if attributes.has_key?(:'maxUseEnabled')
        self.max_use_enabled = attributes[:'maxUseEnabled']
      end

      if attributes.has_key?(:'name')
        self.name = attributes[:'name']
      end

      if attributes.has_key?(:'powerFormId')
        self.power_form_id = attributes[:'powerFormId']
      end

      if attributes.has_key?(:'powerFormUrl')
        self.power_form_url = attributes[:'powerFormUrl']
      end

      if attributes.has_key?(:'recipients')
        if (value = attributes[:'recipients']).is_a?(Array)
          self.recipients = value
        end
      end

      if attributes.has_key?(:'senderName')
        self.sender_name = attributes[:'senderName']
      end

      if attributes.has_key?(:'senderUserId')
        self.sender_user_id = attributes[:'senderUserId']
      end

      if attributes.has_key?(:'signingMode')
        self.signing_mode = attributes[:'signingMode']
      end

      if attributes.has_key?(:'templateId')
        self.template_id = attributes[:'templateId']
      end

      if attributes.has_key?(:'templateName')
        self.template_name = attributes[:'templateName']
      end

      if attributes.has_key?(:'timesUsed')
        self.times_used = attributes[:'timesUsed']
      end

      if attributes.has_key?(:'uri')
        self.uri = attributes[:'uri']
      end

      if attributes.has_key?(:'usesRemaining')
        self.uses_remaining = attributes[:'usesRemaining']
      end
    end

    # Show invalid properties with the reasons. Usually used together with valid?
    # @return Array for valid properties with the reasons
    def list_invalid_properties
      invalid_properties = Array.new
      invalid_properties
    end

    # Check to see if the all the properties in the model are valid
    # @return true if the model is valid
    def valid?
      true
    end

    # Checks equality by comparing each attribute.
    # @param [Object] Object to be compared
    def ==(o)
      return true if self.equal?(o)
      self.class == o.class &&
          created_by == o.created_by &&
          created_date_time == o.created_date_time &&
          email_body == o.email_body &&
          email_subject == o.email_subject &&
          envelopes == o.envelopes &&
          error_details == o.error_details &&
          instructions == o.instructions &&
          is_active == o.is_active &&
          last_used == o.last_used &&
          limit_use_interval == o.limit_use_interval &&
          limit_use_interval_enabled == o.limit_use_interval_enabled &&
          limit_use_interval_units == o.limit_use_interval_units &&
          max_use_enabled == o.max_use_enabled &&
          name == o.name &&
          power_form_id == o.power_form_id &&
          power_form_url == o.power_form_url &&
          recipients == o.recipients &&
          sender_name == o.sender_name &&
          sender_user_id == o.sender_user_id &&
          signing_mode == o.signing_mode &&
          template_id == o.template_id &&
          template_name == o.template_name &&
          times_used == o.times_used &&
          uri == o.uri &&
          uses_remaining == o.uses_remaining
    end

    # @see the `==` method
    # @param [Object] Object to be compared
    def eql?(o)
      self == o
    end

    # Calculates hash code according to all attributes.
    # @return [Fixnum] Hash code
    def hash
      [created_by, created_date_time, email_body, email_subject, envelopes, error_details, instructions, is_active, last_used, limit_use_interval, limit_use_interval_enabled, limit_use_interval_units, max_use_enabled, name, power_form_id, power_form_url, recipients, sender_name, sender_user_id, signing_mode, template_id, template_name, times_used, uri, uses_remaining].hash
    end

    # Builds the object from hash
    # @param [Hash] attributes Model attributes in the form of hash
    # @return [Object] Returns the model itself
    def build_from_hash(attributes)
      return nil unless attributes.is_a?(Hash)
      self.class.swagger_types.each_pair do |key, type|
        if type =~ /\AArray<(.*)>/i
          # check to ensure the input is an array given that the attribute
          # is documented as an array but the input is not
          if attributes[self.class.attribute_map[key]].is_a?(Array)
            self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
          end
        elsif !attributes[self.class.attribute_map[key]].nil?
          self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
        end # or else data not found in attributes(hash), not an issue as the data can be optional
      end

      self
    end

    # Deserializes the data based on type
    # @param string type Data type
    # @param string value Value to be deserialized
    # @return [Object] Deserialized data
    def _deserialize(type, value)
      case type.to_sym
      when :DateTime
        DateTime.parse(value)
      when :Date
        Date.parse(value)
      when :String
        value.to_s
      when :Integer
        value.to_i
      when :Float
        value.to_f
      when :BOOLEAN
        if value.to_s =~ /\A(true|t|yes|y|1)\z/i
          true
        else
          false
        end
      when :Object
        # generic object (usually a Hash), return directly
        value
      when /\AArray<(?<inner_type>.+)>\z/
        inner_type = Regexp.last_match[:inner_type]
        value.map { |v| _deserialize(inner_type, v) }
      when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
        k_type = Regexp.last_match[:k_type]
        v_type = Regexp.last_match[:v_type]
        {}.tap do |hash|
          value.each do |k, v|
            hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
          end
        end
      else # model
        temp_model = DocuSign_eSign.const_get(type).new
        temp_model.build_from_hash(value)
      end
    end

    # Returns the string representation of the object
    # @return [String] String presentation of the object
    def to_s
      to_hash.to_s
    end

    # to_body is an alias to to_hash (backward compatibility)
    # @return [Hash] Returns the object in the form of hash
    def to_body
      to_hash
    end

    # Returns the object in the form of hash
    # @return [Hash] Returns the object in the form of hash
    def to_hash
      hash = {}
      self.class.attribute_map.each_pair do |attr, param|
        value = self.send(attr)
        next if value.nil?
        hash[param] = _to_hash(value)
      end
      hash
    end

    # Outputs non-array value in the form of hash
    # For object, use to_hash. Otherwise, just return the value
    # @param [Object] value Any valid value
    # @return [Hash] Returns the value in the form of hash
    def _to_hash(value)
      if value.is_a?(Array)
        value.compact.map { |v| _to_hash(v) }
      elsif value.is_a?(Hash)
        {}.tap do |hash|
          value.each { |k, v| hash[k] = _to_hash(v) }
        end
      elsif value.respond_to? :to_hash
        value.to_hash
      else
        value
      end
    end

  end
end
