=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 each component of an address.
  class UsComponents
    # The numeric or alphanumeric part of an address preceding the street name. Often the house, building, or PO Box number.
    attr_accessor :primary_number

    # Geographic direction preceding a street name (`N`, `S`, `E`, `W`, `NE`, `SW`, `SE`, `NW`). 
    attr_accessor :street_predirection

    # The name of the street.
    attr_accessor :street_name

    # The standard USPS abbreviation for the street suffix (`ST`, `AVE`, `BLVD`, etc). 
    attr_accessor :street_suffix

    # Geographic direction following a street name (`N`, `S`, `E`, `W`, `NE`, `SW`, `SE`, `NW`). 
    attr_accessor :street_postdirection

    # The standard USPS abbreviation describing the `components[secondary_number]` (`STE`, `APT`, `BLDG`, etc). 
    attr_accessor :secondary_designator

    # Number of the apartment/unit/etc. 
    attr_accessor :secondary_number

    # Designator of a [CMRA-authorized](https://en.wikipedia.org/wiki/Commercial_mail_receiving_agency) private mailbox. 
    attr_accessor :pmb_designator

    # Number of a [CMRA-authorized](https://en.wikipedia.org/wiki/Commercial_mail_receiving_agency) private mailbox. 
    attr_accessor :pmb_number

    # An extra (often unnecessary) secondary designator provided with the input address. 
    attr_accessor :extra_secondary_designator

    # An extra (often unnecessary) secondary number provided with the input address. 
    attr_accessor :extra_secondary_number

    attr_accessor :city

    # The [ISO 3166-2](https://en.wikipedia.org/wiki/ISO_3166-2) two letter code for the state. 
    attr_accessor :state

    # The 5-digit ZIP code
    attr_accessor :zip_code

    attr_accessor :zip_code_plus_4

    attr_accessor :zip_code_type

    # A 12-digit identifier that uniquely identifies a delivery point (location where mail can be sent and received). It consists of the 5-digit ZIP code (`zip_code`), 4-digit ZIP+4 add-on (`zip_code_plus_4`), 2-digit delivery point, and 1-digit delivery point check digit. 
    attr_accessor :delivery_point_barcode

    # Uses USPS's [Residential Delivery Indicator (RDI)](https://www.usps.com/nationalpremieraccounts/rdi.htm) to identify whether an address is classified as residential or business. Possible values are: * `residential` –– The address is residential or a PO Box. * `commercial` –– The address is commercial. * `''` –– Not enough information provided to be determined. 
    attr_accessor :address_type

    # A description of the type of address. Populated if a DPV match is made (`deliverability_analysis[dpv_confirmation]` is `Y`, `S`, or `D`). For more detailed information about each record type, see [US Verification Details](#tag/US-Verification-Types). 
    attr_accessor :record_type

    # Designates whether or not the address is the default address for a building containing multiple delivery points. 
    attr_accessor :default_building_address

    # County name of the address city.
    attr_accessor :county

    # A 5-digit [FIPS county code](https://en.wikipedia.org/wiki/FIPS_county_code) which uniquely identifies `components[county]`. It consists of a 2-digit state code and a 3-digit county code. 
    attr_accessor :county_fips

    # A 4-character code assigned to a mail delivery route within a ZIP code. 
    attr_accessor :carrier_route

    # The type of `components[carrier_route]`. For more detailed information about each carrier route type, see [US Verification Details](#tag/US-Verification-Types). 
    attr_accessor :carrier_route_type

    # Indicates the mailing facility for an address only supports PO Box deliveries and other forms of mail delivery are not available. 
    attr_accessor :po_box_only_flag

    # A positive or negative decimal indicating the geographic latitude of the address, specifying the north-to-south position of a location. This should be used with `longitude` to pinpoint locations on a map. Will not be returned for undeliverable addresses or military addresses (state is `AA`, `AE`, or `AP`). 
    attr_accessor :latitude

    # A positive or negative decimal indicating the geographic longitude of the address, specifying the north-to-south position of a location. This should be used with `latitude` to pinpoint locations on a map. Will not be returned for undeliverable addresses or military addresses (state is `AA`, `AE`, or `AP`). 
    attr_accessor :longitude

    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
      {
        :'primary_number' => :'primary_number',
        :'street_predirection' => :'street_predirection',
        :'street_name' => :'street_name',
        :'street_suffix' => :'street_suffix',
        :'street_postdirection' => :'street_postdirection',
        :'secondary_designator' => :'secondary_designator',
        :'secondary_number' => :'secondary_number',
        :'pmb_designator' => :'pmb_designator',
        :'pmb_number' => :'pmb_number',
        :'extra_secondary_designator' => :'extra_secondary_designator',
        :'extra_secondary_number' => :'extra_secondary_number',
        :'city' => :'city',
        :'state' => :'state',
        :'zip_code' => :'zip_code',
        :'zip_code_plus_4' => :'zip_code_plus_4',
        :'zip_code_type' => :'zip_code_type',
        :'delivery_point_barcode' => :'delivery_point_barcode',
        :'address_type' => :'address_type',
        :'record_type' => :'record_type',
        :'default_building_address' => :'default_building_address',
        :'county' => :'county',
        :'county_fips' => :'county_fips',
        :'carrier_route' => :'carrier_route',
        :'carrier_route_type' => :'carrier_route_type',
        :'po_box_only_flag' => :'po_box_only_flag',
        :'latitude' => :'latitude',
        :'longitude' => :'longitude'
      }
    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
      {
        :'primary_number' => :'String',
        :'street_predirection' => :'String',
        :'street_name' => :'String',
        :'street_suffix' => :'String',
        :'street_postdirection' => :'String',
        :'secondary_designator' => :'String',
        :'secondary_number' => :'String',
        :'pmb_designator' => :'String',
        :'pmb_number' => :'String',
        :'extra_secondary_designator' => :'String',
        :'extra_secondary_number' => :'String',
        :'city' => :'String',
        :'state' => :'String',
        :'zip_code' => :'String',
        :'zip_code_plus_4' => :'String',
        :'zip_code_type' => :'ZipCodeType',
        :'delivery_point_barcode' => :'String',
        :'address_type' => :'String',
        :'record_type' => :'String',
        :'default_building_address' => :'Boolean',
        :'county' => :'String',
        :'county_fips' => :'String',
        :'carrier_route' => :'String',
        :'carrier_route_type' => :'String',
        :'po_box_only_flag' => :'String',
        :'latitude' => :'Float',
        :'longitude' => :'Float'
      }
    end

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      if @state.to_s.length > 2
        invalid_properties.push('invalid value for "state", the character length must be smaller than or equal to 2.')
      end

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

      pattern = Regexp.new(/(^$)|(^\d{5}$)/)
      if @zip_code !~ pattern
        invalid_properties.push("invalid value for \"zip_code\", must conform to the pattern #{pattern}.")
      end

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

      pattern = Regexp.new(/^(\d{4})?$/)
      if @zip_code_plus_4 !~ pattern
        invalid_properties.push("invalid value for \"zip_code_plus_4\", must conform to the pattern #{pattern}.")
      end

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

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

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

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

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

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

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

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

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

      if @po_box_only_flag.nil?
        invalid_properties.push('invalid value for "po_box_only_flag", po_box_only_flag 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 @primary_number.nil?
      return false if @street_predirection.nil?
      street_predirection_validator = EnumAttributeValidator.new('String', ["N", "S", "E", "W", "NE", "SW", "SE", "NW", ""])
      return false unless street_predirection_validator.valid?(@street_predirection)
      return false if @street_name.nil?
      return false if @street_suffix.nil?
      return false if @street_postdirection.nil?
      street_postdirection_validator = EnumAttributeValidator.new('String', ["N", "S", "E", "W", "NE", "SW", "SE", "NW", ""])
      return false unless street_postdirection_validator.valid?(@street_postdirection)
      return false if @secondary_designator.nil?
      return false if @secondary_number.nil?
      return false if @pmb_designator.nil?
      return false if @pmb_number.nil?
      return false if @extra_secondary_designator.nil?
      return false if @extra_secondary_number.nil?
      return false if @city.nil?
      return false if @city.to_s.length > 200
      return false if @state.nil?
      return false if @state.to_s.length > 2
      return false if @zip_code.nil?
      return false if @zip_code !~ Regexp.new(/(^$)|(^\d{5}$)/)
      return false if @zip_code_plus_4.nil?
      return false if @zip_code_plus_4 !~ Regexp.new(/^(\d{4})?$/)
      return false if @zip_code_type.nil?
      return false if @delivery_point_barcode.nil?
      return false if @address_type.nil?
      address_type_validator = EnumAttributeValidator.new('String', ["residential", "commercial", ""])
      return false unless address_type_validator.valid?(@address_type)
      return false if @record_type.nil?
      record_type_validator = EnumAttributeValidator.new('String', ["street", "highrise", "firm", "po_box", "rural_route", "general_delivery", ""])
      return false unless record_type_validator.valid?(@record_type)
      return false if @default_building_address.nil?
      return false if @county.nil?
      return false if @county_fips.nil?
      return false if @carrier_route.nil?
      return false if @carrier_route_type.nil?
      carrier_route_type_validator = EnumAttributeValidator.new('String', ["city_delivery", "rural_route", "highway_contract", "po_box", "general_delivery", ""])
      return false unless carrier_route_type_validator.valid?(@carrier_route_type)
      return false if @po_box_only_flag.nil?
      po_box_only_flag_validator = EnumAttributeValidator.new('String', ["Y", "N", ""])
      return false unless po_box_only_flag_validator.valid?(@po_box_only_flag)
      true
    end

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

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

    # Custom attribute writer method with validation
    # @param [Object] city Value to be assigned
    def city=(city)
      if city.nil?
        fail ArgumentError, 'city cannot be nil'
      end

      if city.to_s.length > 200
        fail ArgumentError, 'invalid value for "city", the character length must be smaller than or equal to 200.'
      end

      @city = city
    end

    # Custom attribute writer method with validation
    # @param [Object] state Value to be assigned
    def state=(state)
      if state.nil?
        fail ArgumentError, 'state cannot be nil'
      end

      if state.to_s.length > 2
        fail ArgumentError, 'invalid value for "state", the character length must be smaller than or equal to 2.'
      end

      @state = state
    end

    # Custom attribute writer method with validation
    # @param [Object] zip_code Value to be assigned
    def zip_code=(zip_code)
      if zip_code.nil?
        fail ArgumentError, 'zip_code cannot be nil'
      end

      pattern = Regexp.new(/(^$)|(^\d{5}$)/)
      if zip_code !~ pattern
        fail ArgumentError, "invalid value for \"zip_code\", must conform to the pattern #{pattern}."
      end

      @zip_code = zip_code
    end

    # Custom attribute writer method with validation
    # @param [Object] zip_code_plus_4 Value to be assigned
    def zip_code_plus_4=(zip_code_plus_4)
      if zip_code_plus_4.nil?
        fail ArgumentError, 'zip_code_plus_4 cannot be nil'
      end

      pattern = Regexp.new(/^(\d{4})?$/)
      if zip_code_plus_4 !~ pattern
        fail ArgumentError, "invalid value for \"zip_code_plus_4\", must conform to the pattern #{pattern}."
      end

      @zip_code_plus_4 = zip_code_plus_4
    end

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

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

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

    # Custom attribute writer method checking allowed values (enum).
    # @param [Object] po_box_only_flag Object to be assigned
    def po_box_only_flag=(po_box_only_flag)
      validator = EnumAttributeValidator.new('String', ["Y", "N", ""])
      unless validator.valid?(po_box_only_flag)
        fail ArgumentError, "invalid value for \"po_box_only_flag\", must be one of #{validator.allowable_values}."
      end
      @po_box_only_flag = po_box_only_flag
    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 &&
          primary_number == o.primary_number &&
          street_predirection == o.street_predirection &&
          street_name == o.street_name &&
          street_suffix == o.street_suffix &&
          street_postdirection == o.street_postdirection &&
          secondary_designator == o.secondary_designator &&
          secondary_number == o.secondary_number &&
          pmb_designator == o.pmb_designator &&
          pmb_number == o.pmb_number &&
          extra_secondary_designator == o.extra_secondary_designator &&
          extra_secondary_number == o.extra_secondary_number &&
          city == o.city &&
          state == o.state &&
          zip_code == o.zip_code &&
          zip_code_plus_4 == o.zip_code_plus_4 &&
          zip_code_type == o.zip_code_type &&
          delivery_point_barcode == o.delivery_point_barcode &&
          address_type == o.address_type &&
          record_type == o.record_type &&
          default_building_address == o.default_building_address &&
          county == o.county &&
          county_fips == o.county_fips &&
          carrier_route == o.carrier_route &&
          carrier_route_type == o.carrier_route_type &&
          po_box_only_flag == o.po_box_only_flag &&
          latitude == o.latitude &&
          longitude == o.longitude
    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
      [primary_number, street_predirection, street_name, street_suffix, street_postdirection, secondary_designator, secondary_number, pmb_designator, pmb_number, extra_secondary_designator, extra_secondary_number, city, state, zip_code, zip_code_plus_4, zip_code_type, delivery_point_barcode, address_type, record_type, default_building_address, county, county_fips, carrier_route, carrier_route_type, po_box_only_flag, latitude, longitude].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
