=begin
#Cloudsmith API

#The API to the Cloudsmith Service

OpenAPI spec version: v1
Contact: support@cloudsmith.io
Generated by: https://github.com/swagger-api/swagger-codegen.git
Swagger Codegen version: 2.4.26

=end

require 'date'

module CloudsmithApi
  class Repository
    # Base URL from which packages and other artifacts are downloaded.
    attr_accessor :cdn_url

    # 
    attr_accessor :created_at

    # 
    attr_accessor :deleted_at

    # A description of the repository's purpose/contents.
    attr_accessor :description

    # 
    attr_accessor :gpg_keys

    # If checked, files contained in packages will be indexed, which increase the synchronisation time required for packages. Note that it is recommended you keep this enabled unless the synchronisation time is significantly impacted.
    attr_accessor :index_files

    # 
    attr_accessor :is_open_source

    # 
    attr_accessor :is_private

    # 
    attr_accessor :is_public

    # A descriptive name for the repository.
    attr_accessor :name

    # Namespace to which this repository belongs.
    attr_accessor :namespace

    # API endpoint where data about this namespace can be retrieved.
    attr_accessor :namespace_url

    # The number of downloads for packages in the repository.
    attr_accessor :num_downloads

    # The number of packages in the repository.
    attr_accessor :package_count

    # The number of groups in the repository.
    attr_accessor :package_group_count

    # The repository type changes how it is accessed and billed. Private repositories can only be used on paid plans, but are visible only to you or authorised delegates. Open-Source repositories are always visible to everyone and are restricted by licensing, but are free to use and come with generous bandwidth/storage. You can only select Open-Source at repository creation time.
    attr_accessor :repository_type

    # The repository type changes how it is accessed and billed. Private repositories can only be used on paid plans, but are visible only to you or authorised delegates. Public repositories are free to use on all plans and visible to all Cloudsmith users.
    attr_accessor :repository_type_str

    # Website URL for this repository.
    attr_accessor :self_html_url

    # API endpoint where data about this repository can be retrieved.
    attr_accessor :self_url

    # The calculated size of the repository.
    attr_accessor :size

    # The calculated size of the repository (human readable).
    attr_accessor :size_str

    # The slug identifies the repository in URIs.
    attr_accessor :slug

    # The slug_perm immutably identifies the repository. It will never change once a repository has been created.
    attr_accessor :slug_perm

    # The Cloudsmith region in which package files are stored.
    attr_accessor :storage_region

    # Attribute mapping from ruby-style variable name to JSON key.
    def self.attribute_map
      {
        :'cdn_url' => :'cdn_url',
        :'created_at' => :'created_at',
        :'deleted_at' => :'deleted_at',
        :'description' => :'description',
        :'gpg_keys' => :'gpg_keys',
        :'index_files' => :'index_files',
        :'is_open_source' => :'is_open_source',
        :'is_private' => :'is_private',
        :'is_public' => :'is_public',
        :'name' => :'name',
        :'namespace' => :'namespace',
        :'namespace_url' => :'namespace_url',
        :'num_downloads' => :'num_downloads',
        :'package_count' => :'package_count',
        :'package_group_count' => :'package_group_count',
        :'repository_type' => :'repository_type',
        :'repository_type_str' => :'repository_type_str',
        :'self_html_url' => :'self_html_url',
        :'self_url' => :'self_url',
        :'size' => :'size',
        :'size_str' => :'size_str',
        :'slug' => :'slug',
        :'slug_perm' => :'slug_perm',
        :'storage_region' => :'storage_region'
      }
    end

    # Attribute type mapping.
    def self.swagger_types
      {
        :'cdn_url' => :'String',
        :'created_at' => :'String',
        :'deleted_at' => :'String',
        :'description' => :'String',
        :'gpg_keys' => :'Array<ReposGpgKeys>',
        :'index_files' => :'BOOLEAN',
        :'is_open_source' => :'BOOLEAN',
        :'is_private' => :'BOOLEAN',
        :'is_public' => :'BOOLEAN',
        :'name' => :'String',
        :'namespace' => :'String',
        :'namespace_url' => :'String',
        :'num_downloads' => :'Integer',
        :'package_count' => :'Integer',
        :'package_group_count' => :'Integer',
        :'repository_type' => :'String',
        :'repository_type_str' => :'String',
        :'self_html_url' => :'String',
        :'self_url' => :'String',
        :'size' => :'Integer',
        :'size_str' => :'String',
        :'slug' => :'String',
        :'slug_perm' => :'String',
        :'storage_region' => :'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?(:'cdn_url')
        self.cdn_url = attributes[:'cdn_url']
      end

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      if attributes.has_key?(:'storage_region')
        self.storage_region = attributes[:'storage_region']
      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

      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?
      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 &&
          cdn_url == o.cdn_url &&
          created_at == o.created_at &&
          deleted_at == o.deleted_at &&
          description == o.description &&
          gpg_keys == o.gpg_keys &&
          index_files == o.index_files &&
          is_open_source == o.is_open_source &&
          is_private == o.is_private &&
          is_public == o.is_public &&
          name == o.name &&
          namespace == o.namespace &&
          namespace_url == o.namespace_url &&
          num_downloads == o.num_downloads &&
          package_count == o.package_count &&
          package_group_count == o.package_group_count &&
          repository_type == o.repository_type &&
          repository_type_str == o.repository_type_str &&
          self_html_url == o.self_html_url &&
          self_url == o.self_url &&
          size == o.size &&
          size_str == o.size_str &&
          slug == o.slug &&
          slug_perm == o.slug_perm &&
          storage_region == o.storage_region
    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
      [cdn_url, created_at, deleted_at, description, gpg_keys, index_files, is_open_source, is_private, is_public, name, namespace, namespace_url, num_downloads, package_count, package_group_count, repository_type, repository_type_str, self_html_url, self_url, size, size_str, slug, slug_perm, storage_region].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 = CloudsmithApi.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