=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
  # A nested object containing a breakdown of the deliverability of an address.
  class DeliverabilityAnalysis
    # Result of Delivery Point Validation (DPV), which determines whether or not the address is deliverable by the USPS. Possible values are: * `Y` –– The address is deliverable by the USPS. * `S` –– The address is deliverable by removing the provided secondary unit designator. This information may be incorrect or unnecessary. * `D` –– The address is deliverable to the building's default address but is missing a secondary unit designator and/or number.   There is a chance the mail will not reach the intended recipient. * `N` –– The address is not deliverable according to the USPS, but parts of the address are valid (such as the street and ZIP code). * `''` –– This address is not deliverable. No matching street could be found within the city or ZIP code. 
    attr_accessor :dpv_confirmation

    # indicates whether or not the address is [CMRA-authorized](https://en.wikipedia.org/wiki/Commercial_mail_receiving_agency). Possible values are: * `Y` –– Address is CMRA-authorized. * `N` –– Address is not CMRA-authorized. * `''` –– A DPV match is not made (`deliverability_analysis[dpv_confirmation]` is `N` or an empty string). 
    attr_accessor :dpv_cmra

    # indicates that an address was once deliverable, but has become vacant and is no longer receiving deliveries. Possible values are: * `Y` –– Address is vacant. * `N` –– Address is not vacant. * `''` –– A DPV match is not made (`deliverability_analysis[dpv_confirmation]` is `N` or an empty string). 
    attr_accessor :dpv_vacant

    # Corresponds to the USPS field `dpv_no_stat`. Indicates that an address has been vacated in the recent past, and is no longer receiving deliveries. If it's been unoccupied for 90+ days, or temporarily vacant, this will be flagged. Possible values are: * `Y` –– Address is active. * `N` –– Address is not active. * `''` –– A DPV match is not made (`deliverability_analysis[dpv_confirmation]` is `N` or an empty string). 
    attr_accessor :dpv_active

    # Indicates the reason why an address is vacant or no longer receiving deliveries. Possible values are: * `01` –– Address does not receive mail from the USPS directly, but is serviced by a drop address. * `02` –– Address not yet deliverable. * `03` –– A DPV match is not made (`deliverability_analysis[dpv_confirmation]` is `N` or an empty string). * `04` –– Address is a College, Military Zone, or other type. * `05` –– Address no longer receives deliveries. * `06` –– Address is missing required secondary information. * `''` –– A DPV match is not made or the address is active. 
    attr_accessor :dpv_inactive_reason

    # Indicates a street address for which mail is delivered to a PO Box. Possible values are: * `Y` –– Address is a PO Box throwback delivery point. * `N` –– Address is not a PO Box throwback delivery point. * `''` –– A DPV match is not made (`deliverability_analysis[dpv_confirmation]` is `N` or an empty string). 
    attr_accessor :dpv_throwback

    # Indicates whether deliveries are not performed on one or more days of the week at an address. Possible values are: * `Y` –– Mail delivery does not occur on some days of the week. * `N` –– Mail delivery occurs every day of the week. * `''` –– A DPV match is not made (`deliverability_analysis[dpv_confirmation]` is `N` or an empty string). 
    attr_accessor :dpv_non_delivery_day_flag

    # Indicates days of the week (starting on Sunday) deliveries are not performed at an address. For example: * `YNNNNNN` –– Mail delivery does not occur on Sunday's. * `NYNNNYN` –– Mail delivery does not occur on Monday's or Friday's. * `''` –– A DPV match is not made (`deliverability_analysis[dpv_confirmation]` is `N` or an empty string) or address receives mail every day of the week (`deliverability_analysis[dpv_non_delivery_day_flag]` is `N` or an empty string). 
    attr_accessor :dpv_non_delivery_day_values

    # Indicates packages to this address will not be left due to security concerns. Possible values are: * `Y` –– Address does not have a secure mailbox. * `N` –– Address has a secure mailbox. * `''` –– A DPV match is not made (`deliverability_analysis[dpv_confirmation]` is `N` or an empty string). 
    attr_accessor :dpv_no_secure_location

    # Indicates the door of the address is not accessible for mail delivery. Possible values are: * `Y` –– Door is not accessible. * `N` –– Door is accessible. * `''` –– A DPV match is not made (`deliverability_analysis[dpv_confirmation]` is `N` or an empty string). 
    attr_accessor :dpv_door_not_accessible

    # An array of 2-character strings that gives more insight into how `deliverability_analysis[dpv_confirmation]` was determined. Will always include at least 1 string, and can include up to 3. For details, see [US Verification Details](#tag/US-Verification-Types). 
    attr_accessor :dpv_footnotes

    # indicates whether or not an address has been flagged in the [Early Warning System](https://docs.informatica.com/data-engineering/data-engineering-quality/10-4-0/address-validator-port-reference/postal-carrier-certification-data-ports/early-warning-system-return-code.html), meaning the address is under development and not yet ready to receive mail. However, it should become available in a few months. 
    attr_accessor :ews_match

    # indicates whether this address has been converted by [LACS<sup>Link</sup>](https://postalpro.usps.com/address-quality/lacslink). LACS<sup>Link</sup> corrects outdated addresses into their modern counterparts. Possible values are: * `Y` –– New address produced with a matching record in LACS<sup>Link</sup>. * `N` –– New address could not be produced with a matching record in LACS<sup>Link</sup>. * `''` –– A DPV match is not made (`deliverability_analysis[dpv_confirmation]` is `N` or an empty string). 
    attr_accessor :lacs_indicator

    # A code indicating how `deliverability_analysis[lacs_indicator]` was determined. Possible values are: * `A` — A new address was produced because a match was found in LACS<sup>Link</sup>. * `92` — A LACS<sup>Link</sup> record was matched after dropping secondary information. * `14` — A match was found in LACS<sup>Link</sup>, but could not be converted to a deliverable address. * `00` — A match was not found in LACS<sup>Link</sup>, and no new address was produced. * `''` — LACS<sup>Link</sup> was not attempted. 
    attr_accessor :lacs_return_code

    # A return code that indicates whether the address was matched and corrected by [Suite<sup>Link</sup>](https://postalpro.usps.com/address-quality-solutions/suitelink). Suite<sup>Link</sup> attempts to provide secondary information to business addresses. Possible values are: * `A` –– A Suite<sup>Link</sup> match was found and secondary information was added. * `00` –– A Suite<sup>Link</sup> match could not be found and no secondary information was added. * `''` –– Suite<sup>Link</sup> lookup was not attempted. 
    attr_accessor :suite_return_code

    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
      {
        :'dpv_confirmation' => :'dpv_confirmation',
        :'dpv_cmra' => :'dpv_cmra',
        :'dpv_vacant' => :'dpv_vacant',
        :'dpv_active' => :'dpv_active',
        :'dpv_inactive_reason' => :'dpv_inactive_reason',
        :'dpv_throwback' => :'dpv_throwback',
        :'dpv_non_delivery_day_flag' => :'dpv_non_delivery_day_flag',
        :'dpv_non_delivery_day_values' => :'dpv_non_delivery_day_values',
        :'dpv_no_secure_location' => :'dpv_no_secure_location',
        :'dpv_door_not_accessible' => :'dpv_door_not_accessible',
        :'dpv_footnotes' => :'dpv_footnotes',
        :'ews_match' => :'ews_match',
        :'lacs_indicator' => :'lacs_indicator',
        :'lacs_return_code' => :'lacs_return_code',
        :'suite_return_code' => :'suite_return_code'
      }
    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
      {
        :'dpv_confirmation' => :'String',
        :'dpv_cmra' => :'String',
        :'dpv_vacant' => :'String',
        :'dpv_active' => :'String',
        :'dpv_inactive_reason' => :'String',
        :'dpv_throwback' => :'String',
        :'dpv_non_delivery_day_flag' => :'String',
        :'dpv_non_delivery_day_values' => :'String',
        :'dpv_no_secure_location' => :'String',
        :'dpv_door_not_accessible' => :'String',
        :'dpv_footnotes' => :'Array<DpvFootnote>',
        :'ews_match' => :'Boolean',
        :'lacs_indicator' => :'String',
        :'lacs_return_code' => :'String',
        :'suite_return_code' => :'String'
      }
    end

    # List of attributes with nullable: true
    def self.openapi_nullable
      Set.new([
      ])
    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::DeliverabilityAnalysis` 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::DeliverabilityAnalysis`. 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?(:'dpv_confirmation')
        self.dpv_confirmation = attributes[:'dpv_confirmation']
      end

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      if @suite_return_code.nil?
        invalid_properties.push('invalid value for "suite_return_code", suite_return_code 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 @dpv_confirmation.nil?
      dpv_confirmation_validator = EnumAttributeValidator.new('String', ["Y", "S", "D", "N", ""])
      return false unless dpv_confirmation_validator.valid?(@dpv_confirmation)
      return false if @dpv_cmra.nil?
      dpv_cmra_validator = EnumAttributeValidator.new('String', ["Y", "N", ""])
      return false unless dpv_cmra_validator.valid?(@dpv_cmra)
      return false if @dpv_vacant.nil?
      dpv_vacant_validator = EnumAttributeValidator.new('String', ["Y", "N", ""])
      return false unless dpv_vacant_validator.valid?(@dpv_vacant)
      return false if @dpv_active.nil?
      dpv_active_validator = EnumAttributeValidator.new('String', ["Y", "N", ""])
      return false unless dpv_active_validator.valid?(@dpv_active)
      return false if @dpv_inactive_reason.nil?
      dpv_inactive_reason_validator = EnumAttributeValidator.new('String', ["01", "02", "03", "04", "05", "06", ""])
      return false unless dpv_inactive_reason_validator.valid?(@dpv_inactive_reason)
      return false if @dpv_throwback.nil?
      dpv_throwback_validator = EnumAttributeValidator.new('String', ["Y", "N", ""])
      return false unless dpv_throwback_validator.valid?(@dpv_throwback)
      return false if @dpv_non_delivery_day_flag.nil?
      dpv_non_delivery_day_flag_validator = EnumAttributeValidator.new('String', ["Y", "N", ""])
      return false unless dpv_non_delivery_day_flag_validator.valid?(@dpv_non_delivery_day_flag)
      return false if @dpv_non_delivery_day_values.nil?
      return false if @dpv_no_secure_location.nil?
      dpv_no_secure_location_validator = EnumAttributeValidator.new('String', ["Y", "N", ""])
      return false unless dpv_no_secure_location_validator.valid?(@dpv_no_secure_location)
      return false if @dpv_door_not_accessible.nil?
      dpv_door_not_accessible_validator = EnumAttributeValidator.new('String', ["Y", "N", ""])
      return false unless dpv_door_not_accessible_validator.valid?(@dpv_door_not_accessible)
      return false if @dpv_footnotes.nil?
      return false if @ews_match.nil?
      return false if @lacs_indicator.nil?
      lacs_indicator_validator = EnumAttributeValidator.new('String', ["Y", "N", ""])
      return false unless lacs_indicator_validator.valid?(@lacs_indicator)
      return false if @lacs_return_code.nil?
      return false if @suite_return_code.nil?
      suite_return_code_validator = EnumAttributeValidator.new('String', ["A", "00", ""])
      return false unless suite_return_code_validator.valid?(@suite_return_code)
      true
    end

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

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

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

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

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

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

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

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

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

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

    # Custom attribute writer method checking allowed values (enum).
    # @param [Object] suite_return_code Object to be assigned
    def suite_return_code=(suite_return_code)
      validator = EnumAttributeValidator.new('String', ["A", "00", ""])
      unless validator.valid?(suite_return_code)
        fail ArgumentError, "invalid value for \"suite_return_code\", must be one of #{validator.allowable_values}."
      end
      @suite_return_code = suite_return_code
    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 &&
          dpv_confirmation == o.dpv_confirmation &&
          dpv_cmra == o.dpv_cmra &&
          dpv_vacant == o.dpv_vacant &&
          dpv_active == o.dpv_active &&
          dpv_inactive_reason == o.dpv_inactive_reason &&
          dpv_throwback == o.dpv_throwback &&
          dpv_non_delivery_day_flag == o.dpv_non_delivery_day_flag &&
          dpv_non_delivery_day_values == o.dpv_non_delivery_day_values &&
          dpv_no_secure_location == o.dpv_no_secure_location &&
          dpv_door_not_accessible == o.dpv_door_not_accessible &&
          dpv_footnotes == o.dpv_footnotes &&
          ews_match == o.ews_match &&
          lacs_indicator == o.lacs_indicator &&
          lacs_return_code == o.lacs_return_code &&
          suite_return_code == o.suite_return_code
    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
      [dpv_confirmation, dpv_cmra, dpv_vacant, dpv_active, dpv_inactive_reason, dpv_throwback, dpv_non_delivery_day_flag, dpv_non_delivery_day_values, dpv_no_secure_location, dpv_door_not_accessible, dpv_footnotes, ews_match, lacs_indicator, lacs_return_code, suite_return_code].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
