=begin
#Flip API

#Description

OpenAPI spec version: 2.0.1
Contact: cloudsupport@telestream.net
Generated by: https://github.com/swagger-api/swagger-codegen.git
Swagger Codegen version: 2.3.1

=end

require 'date'

module TelestreamCloud::Flip

  class FactoryBody
    # AWS access key.
    attr_accessor :aws_access_key

    # AWS secret key.
    attr_accessor :aws_secret_key

    # A region where the factory is located.
    attr_accessor :factory_region

    # A pattern that will be used to locate files in the input bucket. Valid wildcards might be used.
    attr_accessor :input_bucket_file_pattern

    # A name of an input bucket.
    attr_accessor :input_bucket_name

    attr_accessor :input_bucket_recursive

    # Determines how often the input bucket is synchronised.
    attr_accessor :input_bucket_sync_every_n_min

    # Determines whether the Factory should be notified about new files added to the input bucket.
    attr_accessor :input_bucket_watch

    # Name of the Factory.
    attr_accessor :name

    # Specify the directory where the output files should be stored. By default it is not set. More info [here](https://cloud.telestream.net/docs#path-format---know-how).
    attr_accessor :outputs_path_format

    attr_accessor :provider_specific_settings

    # Specify if your files are public or private (private files need authorization url to access). By default this is not set.
    attr_accessor :acl

    # A bucket where processed files will be stored.
    attr_accessor :output_bucket_name

    # Specify if you want to use multi-factor server-side 256-bit AES-256 data encryption with Amazon S3-managed encryption keys (SSE-S3). Each object is encrypted using a unique key which as an additional safeguard is encrypted itself with a master key that S3 regularly rotates. By default this is not set.
    attr_accessor :server_side_encryption

    attr_accessor :storage_credential_attributes

    # Specifies which storage provider the factory should use. Available options: S3: 0, Google Cloud Storage: 1, FTP storage: 2, Google Cloud Interoperability Storage: 5, Flip storage: 7, FASP storage: 8, Azure Blob Storage: 9
    attr_accessor :storage_provider

    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
      {
        :'aws_access_key' => :'aws_access_key',
        :'aws_secret_key' => :'aws_secret_key',
        :'factory_region' => :'factory_region',
        :'input_bucket_file_pattern' => :'input_bucket_file_pattern',
        :'input_bucket_name' => :'input_bucket_name',
        :'input_bucket_recursive' => :'input_bucket_recursive',
        :'input_bucket_sync_every_n_min' => :'input_bucket_sync_every_n_min',
        :'input_bucket_watch' => :'input_bucket_watch',
        :'name' => :'name',
        :'outputs_path_format' => :'outputs_path_format',
        :'provider_specific_settings' => :'provider_specific_settings',
        :'acl' => :'acl',
        :'output_bucket_name' => :'output_bucket_name',
        :'server_side_encryption' => :'server_side_encryption',
        :'storage_credential_attributes' => :'storage_credential_attributes',
        :'storage_provider' => :'storage_provider'
      }
    end

    # Attribute type mapping.
    def self.swagger_types
      {
        :'aws_access_key' => :'String',
        :'aws_secret_key' => :'String',
        :'factory_region' => :'String',
        :'input_bucket_file_pattern' => :'String',
        :'input_bucket_name' => :'String',
        :'input_bucket_recursive' => :'BOOLEAN',
        :'input_bucket_sync_every_n_min' => :'Integer',
        :'input_bucket_watch' => :'BOOLEAN',
        :'name' => :'String',
        :'outputs_path_format' => :'String',
        :'provider_specific_settings' => :'Object',
        :'acl' => :'String',
        :'output_bucket_name' => :'String',
        :'server_side_encryption' => :'BOOLEAN',
        :'storage_credential_attributes' => :'FactoryBodyStorageCredentialAttributes',
        :'storage_provider' => :'Integer'
      }
    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?(:'aws_access_key')
        self.aws_access_key = attributes[:'aws_access_key']
      end

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      return 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 @name.nil?
      acl_validator = EnumAttributeValidator.new('String', ["public", "private"])
      return false unless acl_validator.valid?(@acl)
      return true
    end

    # Custom attribute writer method checking allowed values (enum).
    # @param [Object] acl Object to be assigned
    def acl=(acl)
      validator = EnumAttributeValidator.new('String', ["public", "private"])
      unless validator.valid?(acl)
        fail ArgumentError, "invalid value for 'acl', must be one of #{validator.allowable_values}."
      end
      @acl = acl
    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 &&
          aws_access_key == o.aws_access_key &&
          aws_secret_key == o.aws_secret_key &&
          factory_region == o.factory_region &&
          input_bucket_file_pattern == o.input_bucket_file_pattern &&
          input_bucket_name == o.input_bucket_name &&
          input_bucket_recursive == o.input_bucket_recursive &&
          input_bucket_sync_every_n_min == o.input_bucket_sync_every_n_min &&
          input_bucket_watch == o.input_bucket_watch &&
          name == o.name &&
          outputs_path_format == o.outputs_path_format &&
          provider_specific_settings == o.provider_specific_settings &&
          acl == o.acl &&
          output_bucket_name == o.output_bucket_name &&
          server_side_encryption == o.server_side_encryption &&
          storage_credential_attributes == o.storage_credential_attributes &&
          storage_provider == o.storage_provider
    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
      [aws_access_key, aws_secret_key, factory_region, input_bucket_file_pattern, input_bucket_name, input_bucket_recursive, input_bucket_sync_every_n_min, input_bucket_watch, name, outputs_path_format, provider_specific_settings, acl, output_bucket_name, server_side_encryption, storage_credential_attributes, storage_provider].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 = TelestreamCloud::Flip.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
