=begin
#Lob

#The Lob API is organized around REST. Our API is designed to have predictable, resource-oriented URLs and uses HTTP response codes to indicate any API errors. <p> Looking for our [previous documentation](https://lob.github.io/legacy-docs/)? 

The version of the OpenAPI document: 1.3.0
Contact: lob-openapi@lob.com
Generated by: https://openapi-generator.tech
OpenAPI Generator version: 5.2.1

=end

require 'date'
require 'time'

module Lob
  class IntlVerification
    # Unique identifier prefixed with `intl_ver_`.
    attr_accessor :id

    # The intended recipient, typically a person's or firm's name.
    attr_accessor :recipient

    # The primary delivery line (usually the street address) of the address. 
    attr_accessor :primary_line

    # The secondary delivery line of the address. This field is typically empty but may contain information if `primary_line` is too long. 
    attr_accessor :secondary_line

    # Combination of the following applicable `components`: * `city` * `state` * `zip_code` * `zip_code_plus_4` 
    attr_accessor :last_line

    # The country of the address. Will be returned as a 2 letter country short-name code (ISO 3166).
    attr_accessor :country

    # The coverage level for the country. This represents the maximum level of accuracy an input address can be verified to.  * `SUBBUILDING` - Coverage down to unit numbers. For example, in an apartment or a large building * `HOUSENUMBER/BUILDING` - Coverage down to house number. For example, the address where a house or building may be located * `STREET` - Coverage down to street. This means that we can verify that an street exists in a city, state, country * `LOCALITY` - Coverage down to city, state, or village or province. This means that we can verify that a city, village, province, or state exists in a country. Countries differ in how they define what is a province, state, city, village, etc. This attempts to group eveyrthing together. * `SPARSE` - Some addresses for this country exist in our databases 
    attr_accessor :coverage

    # Summarizes the deliverability of the `intl_verification` object. Possible values are: * `deliverable` — The address is deliverable. * `deliverable_missing_info` — The address is missing some information, but is most likely deliverable. * `undeliverable` — The address is most likely not deliverable. Some components of the address (such as city or postal code) may have been found. * `no_match` — This address is not deliverable. No matching street could be found within the city or postal code. 
    attr_accessor :deliverability

    # The status level for the country. This represents the maximum level of accuracy an input address can be verified to.  * `LV4` - Verified. The input data is correct. All input data was able to match in databases. * `LV3` - Verified. The input data is correct. All input data was able to match in databases <em>after</em> some or all elements were standarized. The input data may also be using outdated city, state, or country names. * `LV2` - Verified. The input data is correct although some input data is unverifiable due to incomplete data. * `LV1` - Verified. The input data is acceptable but in an attempt to standarize user input, errors were introduced. * `LF4` - Fixed. The input data is matched and fixed. (Example: Brighon, UK -> Brighton, UK) * `LF3` - Fixed. The input data is matched and fixed but some elements such as Subbuilding number and house number cannot be checked. * `LF2` - Fixed. The input data is matched but some elements such as Street cannot be checked. * `LF1` - Fixed. The input data is acceptable but in an attempt to standarize user input, errors were introduced. * `LM4` - Missing Info. The input data cannot be corrected completely. * `LM3` - Missing Info. The input data cannot be corrected completely and there were multiple matches found in databases. * `LM2` - Missing Info. The input data cannot be corrected completely and only some elements were found. * `LU1` - Unverified. The input data cannot be corrected or matched. 
    attr_accessor :status

    attr_accessor :components

    # Value is resource type.
    attr_accessor :object

    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
      {
        :'id' => :'id',
        :'recipient' => :'recipient',
        :'primary_line' => :'primary_line',
        :'secondary_line' => :'secondary_line',
        :'last_line' => :'last_line',
        :'country' => :'country',
        :'coverage' => :'coverage',
        :'deliverability' => :'deliverability',
        :'status' => :'status',
        :'components' => :'components',
        :'object' => :'object'
      }
    end

    # Returns all the JSON keys this model knows about
    def self.acceptable_attributes
      attribute_map.values
    end

    # Attribute type mapping.
    def self.openapi_types
      {
        :'id' => :'String',
        :'recipient' => :'String',
        :'primary_line' => :'String',
        :'secondary_line' => :'String',
        :'last_line' => :'String',
        :'country' => :'String',
        :'coverage' => :'String',
        :'deliverability' => :'String',
        :'status' => :'String',
        :'components' => :'IntlComponents',
        :'object' => :'String'
      }
    end

    # List of attributes with nullable: true
    def self.openapi_nullable
      Set.new([
        :'recipient',
      ])
    end

    # Initializes the object
    # @param [Hash] attributes Model attributes in the form of hash
    def initialize(attributes = {})
      if (!attributes.is_a?(Hash))
        fail ArgumentError, "The input argument (attributes) must be a hash in `Lob::IntlVerification` initialize method"
      end

      # check to see if the attribute exists and convert string to symbol for hash key
      attributes = attributes.each_with_object({}) { |(k, v), h|
        if (!self.class.attribute_map.key?(k.to_sym))
          fail ArgumentError, "`#{k}` is not a valid attribute in `Lob::IntlVerification`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
        end
        h[k.to_sym] = v
      }

      if attributes.key?(:'id')
        self.id = attributes[:'id']
      end

      if attributes.key?(:'recipient')
        self.recipient = attributes[:'recipient']
      end

      if attributes.key?(:'primary_line')
        self.primary_line = attributes[:'primary_line']
      end

      if attributes.key?(:'secondary_line')
        self.secondary_line = attributes[:'secondary_line']
      end

      if attributes.key?(:'last_line')
        self.last_line = attributes[:'last_line']
      end

      if attributes.key?(:'country')
        self.country = attributes[:'country']
      end

      if attributes.key?(:'coverage')
        self.coverage = attributes[:'coverage']
      end

      if attributes.key?(:'deliverability')
        self.deliverability = attributes[:'deliverability']
      end

      if attributes.key?(:'status')
        self.status = attributes[:'status']
      end

      if attributes.key?(:'components')
        self.components = attributes[:'components']
      end

      if attributes.key?(:'object')
        self.object = attributes[:'object']
      else
        self.object = 'intl_verification'
      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
      pattern = Regexp.new(/^intl_ver_[a-zA-Z0-9]+$/)
      if !@id.nil? && @id !~ pattern
        invalid_properties.push("invalid value for \"id\", must conform to the pattern #{pattern}.")
      end

      if !@recipient.nil? && @recipient.to_s.length > 500
        invalid_properties.push('invalid value for "recipient", the character length must be smaller than or equal to 500.')
      end

      if !@primary_line.nil? && @primary_line.to_s.length > 200
        invalid_properties.push('invalid value for "primary_line", the character length must be smaller than or equal to 200.')
      end

      if !@secondary_line.nil? && @secondary_line.to_s.length > 500
        invalid_properties.push('invalid value for "secondary_line", the character length must be smaller than or equal to 500.')
      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 !@id.nil? && @id !~ Regexp.new(/^intl_ver_[a-zA-Z0-9]+$/)
      return false if !@recipient.nil? && @recipient.to_s.length > 500
      return false if !@primary_line.nil? && @primary_line.to_s.length > 200
      return false if !@secondary_line.nil? && @secondary_line.to_s.length > 500
      coverage_validator = EnumAttributeValidator.new('String', ["SUBBUILDING", "HOUSENUMBER/BUILDING", "STREET", "LOCALITY", "SPARSE"])
      return false unless coverage_validator.valid?(@coverage)
      deliverability_validator = EnumAttributeValidator.new('String', ["deliverable", "deliverable_missing_info", "undeliverable", "no_match"])
      return false unless deliverability_validator.valid?(@deliverability)
      status_validator = EnumAttributeValidator.new('String', ["LV4", "LV3", "LV2", "LV1", "LF4", "LF3", "LF2", "LF1", "LM4", "LM3", "LM2", "LU1"])
      return false unless status_validator.valid?(@status)
      object_validator = EnumAttributeValidator.new('String', ["intl_verification"])
      return false unless object_validator.valid?(@object)
      true
    end

    # Custom attribute writer method with validation
    # @param [Object] id Value to be assigned
    def id=(id)
      pattern = Regexp.new(/^intl_ver_[a-zA-Z0-9]+$/)
      if !id.nil? && id !~ pattern
        fail ArgumentError, "invalid value for \"id\", must conform to the pattern #{pattern}."
      end

      @id = id
    end

    # Custom attribute writer method with validation
    # @param [Object] recipient Value to be assigned
    def recipient=(recipient)
      if !recipient.nil? && recipient.to_s.length > 500
        fail ArgumentError, 'invalid value for "recipient", the character length must be smaller than or equal to 500.'
      end

      @recipient = recipient
    end

    # Custom attribute writer method with validation
    # @param [Object] primary_line Value to be assigned
    def primary_line=(primary_line)
      if !primary_line.nil? && primary_line.to_s.length > 200
        fail ArgumentError, 'invalid value for "primary_line", the character length must be smaller than or equal to 200.'
      end

      @primary_line = primary_line
    end

    # Custom attribute writer method with validation
    # @param [Object] secondary_line Value to be assigned
    def secondary_line=(secondary_line)
      if !secondary_line.nil? && secondary_line.to_s.length > 500
        fail ArgumentError, 'invalid value for "secondary_line", the character length must be smaller than or equal to 500.'
      end

      @secondary_line = secondary_line
    end

    # Custom attribute writer method checking allowed values (enum).
    # @param [Object] coverage Object to be assigned
    def coverage=(coverage)
      validator = EnumAttributeValidator.new('String', ["SUBBUILDING", "HOUSENUMBER/BUILDING", "STREET", "LOCALITY", "SPARSE"])
      unless validator.valid?(coverage)
        fail ArgumentError, "invalid value for \"coverage\", must be one of #{validator.allowable_values}."
      end
      @coverage = coverage
    end

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

    # Custom attribute writer method checking allowed values (enum).
    # @param [Object] status Object to be assigned
    def status=(status)
      validator = EnumAttributeValidator.new('String', ["LV4", "LV3", "LV2", "LV1", "LF4", "LF3", "LF2", "LF1", "LM4", "LM3", "LM2", "LU1"])
      unless validator.valid?(status)
        fail ArgumentError, "invalid value for \"status\", must be one of #{validator.allowable_values}."
      end
      @status = status
    end

    # Custom attribute writer method checking allowed values (enum).
    # @param [Object] object Object to be assigned
    def object=(object)
      validator = EnumAttributeValidator.new('String', ["intl_verification"])
      unless validator.valid?(object)
        fail ArgumentError, "invalid value for \"object\", must be one of #{validator.allowable_values}."
      end
      @object = object
    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 &&
          id == o.id &&
          recipient == o.recipient &&
          primary_line == o.primary_line &&
          secondary_line == o.secondary_line &&
          last_line == o.last_line &&
          country == o.country &&
          coverage == o.coverage &&
          deliverability == o.deliverability &&
          status == o.status &&
          components == o.components &&
          object == o.object
    end

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

    # Calculates hash code according to all attributes.
    # @return [Integer] Hash code
    def hash
      [id, recipient, primary_line, secondary_line, last_line, country, coverage, deliverability, status, components, object].hash
    end


    # Builds the object from hash
    # @param [Hash] attributes Model attributes in the form of hash
    # @return [Object] Returns the model itself
    def self.build_from_hash(attributes)
      new.build_from_hash(attributes)
    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)
      attributes = attributes.transform_keys(&:to_sym)
      self.class.openapi_types.each_pair do |key, type|
        if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
          self.send("#{key}=", nil) # // guardrails-disable-line
        elsif 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) }) # // guardrails-disable-line
          end
        elsif !attributes[self.class.attribute_map[key]].nil? && type.kind_of?(Array)
          for base_type in type do
            res = _deserialize(base_type, attributes[self.class.attribute_map[key]])
            if !res.nil?
              self.send("#{key}=", res) # // guardrails-disable-line
              break
            end
          end
        elsif !attributes[self.class.attribute_map[key]].nil?
          self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]])) # // guardrails-disable-line
        end
      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 :Time
        Time.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
        # models (e.g. Pet) or oneOf
        klass = Lob.const_get(type)
        klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.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) # // guardrails-disable-line
        if value.nil?
          is_nullable = self.class.openapi_nullable.include?(attr)
          next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
        end

        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
