=begin
#finAPI RESTful Services (alpha build)

#finAPI RESTful Services (alpha build)

OpenAPI spec version: finAPI PSD2-alpha (based on v.1.73.0)

Generated by: https://github.com/swagger-api/swagger-codegen.git
Swagger Codegen version: 2.4.7

=end

require 'date'

module FinapiApi
  # Parameters for a single or collective SEPA direct debit order request
  class RequestSepaDirectDebitParams
    # Identifier of the bank account to which you want to transfer the money.
    attr_accessor :account_id

    # Online banking PIN. Any symbols are allowed. Max length: 170. If a PIN is stored in the bank connection, then this field may remain unset. If finAPI's web form is not required and the field is set though then it will always be used (even if there is some other PIN stored in the bank connection). If you want the user to enter a PIN in finAPI's web form even when a PIN is stored, then just set the field to any value, so that the service recognizes that you wish to use the web form flow.
    attr_accessor :banking_pin

    # Whether to store the PIN. If the PIN is stored, it is not required to pass the PIN again when executing SEPA orders. Default value is 'false'. <br/><br/>NOTES:<br/> - before you set this field to true, please regard the 'pinsAreVolatile' flag of the bank connection that the account belongs to;<br/> - this field is ignored in case when the user will need to use finAPI's web form. The user will be able to decide whether to store the PIN or not in the web form, depending on the 'storeSecretsAvailableInWebForm' setting (see Client Configuration).
    attr_accessor :store_secrets

    # The bank-given ID of the two-step-procedure that should be used for the order. For a list of available two-step-procedures, see the corresponding bank connection (GET /bankConnections). If this field is not set, then the bank connection's default two-step-procedure will be used. Note that in this case, when the bank connection has no default two-step-procedure set, then the response of the service depends on whether you need to use finAPI's web form or not. If you need to use the web form, the user will be prompted to select the two-step-procedure within the web form. If you don't need to use the web form, then the service will return an error (passing a value for this field is required in this case).
    attr_accessor :two_step_procedure_id

    # Type of the direct debit; either <code>BASIC</code> or <code>B2B</code> (Business-To-Business). Please note that an account which supports the basic type must not necessarily support B2B (or vice versa). Check the source account's 'supportedOrders' field to find out which types of direct debit it supports.<br/><br/>
    attr_accessor :direct_debit_type

    # Sequence type of the direct debit. Possible values:<br/><br/>&bull; <code>OOFF</code> - means that this is a one-time direct debit order<br/>&bull; <code>FRST</code> - means that this is the first in a row of multiple direct debit orders<br/>&bull; <code>RCUR</code> - means that this is one (but not the first or final) within a row of multiple direct debit orders<br/>&bull; <code>FNAL</code> - means that this is the final in a row of multiple direct debit orders<br/><br/>
    attr_accessor :sequence_type

    # Execution date for the direct debit(s), in the format 'YYYY-MM-DD'.
    attr_accessor :execution_date

    # This field is only regarded when you pass multiple orders. It determines whether the orders should be processed by the bank as one collective booking (in case of 'false'), or as single bookings (in case of 'true'). Default value is 'false'.
    attr_accessor :single_booking

    # List of the direct debits that you want to execute (may contain at most 15000 items). Please check the account's 'supportedOrders' field to find out whether you can pass multiple direct debits or just one.
    attr_accessor :direct_debits

    # Whether to store the PIN. If the PIN is stored, it is not required to pass the PIN again when executing SEPA orders. Default value is 'false'. <br/><br/>NOTES:<br/> - before you set this field to true, please regard the 'pinsAreVolatile' flag of the bank connection that the account belongs to;<br/> - this field is ignored in case when the user will need to use finAPI's web form. The user will be able to decide whether to store the PIN or not in the web form, depending on the 'storeSecretsAvailableInWebForm' setting (see Client Configuration).<br><br>NOTE: This field is deprecated and will be removed at some point. Use 'storeSecrets' instead.
    attr_accessor :store_pin

    class EnumAttributeValidator
      attr_reader :datatype
      attr_reader :allowable_values

      def initialize(datatype, allowable_values)
        @allowable_values = allowable_values.map do |value|
          case datatype.to_s
          when /Integer/i
            value.to_i
          when /Float/i
            value.to_f
          else
            value
          end
        end
      end

      def valid?(value)
        !value || allowable_values.include?(value)
      end
    end

    # Attribute mapping from ruby-style variable name to JSON key.
    def self.attribute_map
      {
        :'account_id' => :'accountId',
        :'banking_pin' => :'bankingPin',
        :'store_secrets' => :'storeSecrets',
        :'two_step_procedure_id' => :'twoStepProcedureId',
        :'direct_debit_type' => :'directDebitType',
        :'sequence_type' => :'sequenceType',
        :'execution_date' => :'executionDate',
        :'single_booking' => :'singleBooking',
        :'direct_debits' => :'directDebits',
        :'store_pin' => :'storePin'
      }
    end

    # Attribute type mapping.
    def self.swagger_types
      {
        :'account_id' => :'Integer',
        :'banking_pin' => :'String',
        :'store_secrets' => :'BOOLEAN',
        :'two_step_procedure_id' => :'String',
        :'direct_debit_type' => :'String',
        :'sequence_type' => :'String',
        :'execution_date' => :'String',
        :'single_booking' => :'BOOLEAN',
        :'direct_debits' => :'Array<SingleDirectDebitData>',
        :'store_pin' => :'BOOLEAN'
      }
    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?(:'accountId')
        self.account_id = attributes[:'accountId']
      end

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

      if attributes.has_key?(:'storeSecrets')
        self.store_secrets = attributes[:'storeSecrets']
      else
        self.store_secrets = false
      end

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

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

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

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

      if attributes.has_key?(:'singleBooking')
        self.single_booking = attributes[:'singleBooking']
      else
        self.single_booking = false
      end

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

      if attributes.has_key?(:'storePin')
        self.store_pin = attributes[:'storePin']
      else
        self.store_pin = false
      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
      if @account_id.nil?
        invalid_properties.push('invalid value for "account_id", account_id cannot be nil.')
      end

      if @direct_debit_type.nil?
        invalid_properties.push('invalid value for "direct_debit_type", direct_debit_type cannot be nil.')
      end

      if @sequence_type.nil?
        invalid_properties.push('invalid value for "sequence_type", sequence_type cannot be nil.')
      end

      if @execution_date.nil?
        invalid_properties.push('invalid value for "execution_date", execution_date cannot be nil.')
      end

      if @direct_debits.nil?
        invalid_properties.push('invalid value for "direct_debits", direct_debits cannot be nil.')
      end

      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?
      return false if @account_id.nil?
      return false if @direct_debit_type.nil?
      direct_debit_type_validator = EnumAttributeValidator.new('String', ['B2B', 'BASIC'])
      return false unless direct_debit_type_validator.valid?(@direct_debit_type)
      return false if @sequence_type.nil?
      sequence_type_validator = EnumAttributeValidator.new('String', ['OOFF', 'FRST', 'RCUR', 'FNAL'])
      return false unless sequence_type_validator.valid?(@sequence_type)
      return false if @execution_date.nil?
      return false if @direct_debits.nil?
      true
    end

    # Custom attribute writer method checking allowed values (enum).
    # @param [Object] direct_debit_type Object to be assigned
    def direct_debit_type=(direct_debit_type)
      validator = EnumAttributeValidator.new('String', ['B2B', 'BASIC'])
      unless validator.valid?(direct_debit_type)
        fail ArgumentError, 'invalid value for "direct_debit_type", must be one of #{validator.allowable_values}.'
      end
      @direct_debit_type = direct_debit_type
    end

    # Custom attribute writer method checking allowed values (enum).
    # @param [Object] sequence_type Object to be assigned
    def sequence_type=(sequence_type)
      validator = EnumAttributeValidator.new('String', ['OOFF', 'FRST', 'RCUR', 'FNAL'])
      unless validator.valid?(sequence_type)
        fail ArgumentError, 'invalid value for "sequence_type", must be one of #{validator.allowable_values}.'
      end
      @sequence_type = sequence_type
    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 &&
          account_id == o.account_id &&
          banking_pin == o.banking_pin &&
          store_secrets == o.store_secrets &&
          two_step_procedure_id == o.two_step_procedure_id &&
          direct_debit_type == o.direct_debit_type &&
          sequence_type == o.sequence_type &&
          execution_date == o.execution_date &&
          single_booking == o.single_booking &&
          direct_debits == o.direct_debits &&
          store_pin == o.store_pin
    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
      [account_id, banking_pin, store_secrets, two_step_procedure_id, direct_debit_type, sequence_type, execution_date, single_booking, direct_debits, store_pin].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 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 = FinapiApi.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
