=begin
Call Control API

API for blocking phone calls with Call Control. Data is from crowdsourced community blacklist from 12+ million users and government agencies (FTC, FCC, IRS) Try with api_key 'demo', hit explore above, and then try phone numbers 18008472911,13157244022,17275567300,18008276655,12061231234.

OpenAPI spec version: 2015-11-01
Contact: info@kedlin.com
Generated by: https://github.com/swagger-api/swagger-codegen.git


=end

require 'date'

module SwaggerClient
  class CallControlUser
    attr_accessor :phone_number

    attr_accessor :phone_numbe_region

    attr_accessor :white_list

    attr_accessor :black_list

    attr_accessor :quiet_hour_list

    attr_accessor :use_community_blacklist

    attr_accessor :break_through_qh_with_multiple_calls

    attr_accessor :white_list_breaks_qh

    attr_accessor :block_behavior

    attr_accessor :email

    attr_accessor :age

    attr_accessor :gender

    attr_accessor :salutation

    attr_accessor :first_name

    attr_accessor :middle_name

    attr_accessor :last_name

    attr_accessor :suffix

    # Attribute mapping from ruby-style variable name to JSON key.
    def self.attribute_map
      {
        
        :'phone_number' => :'PhoneNumber',
        
        :'phone_numbe_region' => :'PhoneNumbeRegion',
        
        :'white_list' => :'WhiteList',
        
        :'black_list' => :'BlackList',
        
        :'quiet_hour_list' => :'QuietHourList',
        
        :'use_community_blacklist' => :'UseCommunityBlacklist',
        
        :'break_through_qh_with_multiple_calls' => :'BreakThroughQhWithMultipleCalls',
        
        :'white_list_breaks_qh' => :'WhiteListBreaksQh',
        
        :'block_behavior' => :'BlockBehavior',
        
        :'email' => :'Email',
        
        :'age' => :'Age',
        
        :'gender' => :'Gender',
        
        :'salutation' => :'Salutation',
        
        :'first_name' => :'FirstName',
        
        :'middle_name' => :'MiddleName',
        
        :'last_name' => :'LastName',
        
        :'suffix' => :'Suffix'
        
      }
    end

    # Attribute type mapping.
    def self.swagger_types
      {
        :'phone_number' => :'String',
        :'phone_numbe_region' => :'String',
        :'white_list' => :'Array<String>',
        :'black_list' => :'Array<String>',
        :'quiet_hour_list' => :'Array<QuietHour>',
        :'use_community_blacklist' => :'BOOLEAN',
        :'break_through_qh_with_multiple_calls' => :'BOOLEAN',
        :'white_list_breaks_qh' => :'BOOLEAN',
        :'block_behavior' => :'String',
        :'email' => :'String',
        :'age' => :'Integer',
        :'gender' => :'String',
        :'salutation' => :'String',
        :'first_name' => :'String',
        :'middle_name' => :'String',
        :'last_name' => :'String',
        :'suffix' => :'String'
        
      }
    end

    def initialize(attributes = {})
      return unless attributes.is_a?(Hash)

      # convert string to symbol for hash key
      attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}

      
      if attributes[:'PhoneNumber']
        self.phone_number = attributes[:'PhoneNumber']
      end
      
      if attributes[:'PhoneNumbeRegion']
        self.phone_numbe_region = attributes[:'PhoneNumbeRegion']
      end
      
      if attributes[:'WhiteList']
        if (value = attributes[:'WhiteList']).is_a?(Array)
          self.white_list = value
        end
      end
      
      if attributes[:'BlackList']
        if (value = attributes[:'BlackList']).is_a?(Array)
          self.black_list = value
        end
      end
      
      if attributes[:'QuietHourList']
        if (value = attributes[:'QuietHourList']).is_a?(Array)
          self.quiet_hour_list = value
        end
      end
      
      if attributes[:'UseCommunityBlacklist']
        self.use_community_blacklist = attributes[:'UseCommunityBlacklist']
      end
      
      if attributes[:'BreakThroughQhWithMultipleCalls']
        self.break_through_qh_with_multiple_calls = attributes[:'BreakThroughQhWithMultipleCalls']
      end
      
      if attributes[:'WhiteListBreaksQh']
        self.white_list_breaks_qh = attributes[:'WhiteListBreaksQh']
      end
      
      if attributes[:'BlockBehavior']
        self.block_behavior = attributes[:'BlockBehavior']
      end
      
      if attributes[:'Email']
        self.email = attributes[:'Email']
      end
      
      if attributes[:'Age']
        self.age = attributes[:'Age']
      end
      
      if attributes[:'Gender']
        self.gender = attributes[:'Gender']
      end
      
      if attributes[:'Salutation']
        self.salutation = attributes[:'Salutation']
      end
      
      if attributes[:'FirstName']
        self.first_name = attributes[:'FirstName']
      end
      
      if attributes[:'MiddleName']
        self.middle_name = attributes[:'MiddleName']
      end
      
      if attributes[:'LastName']
        self.last_name = attributes[:'LastName']
      end
      
      if attributes[:'Suffix']
        self.suffix = attributes[:'Suffix']
      end
      
    end

    # Custom attribute writer method checking allowed values (enum).
    def block_behavior=(block_behavior)
      allowed_values = ["allow", "voiceMail", "block"]
      if block_behavior && !allowed_values.include?(block_behavior)
        fail "invalid value for 'block_behavior', must be one of #{allowed_values}"
      end
      @block_behavior = block_behavior
    end

    # Check equality by comparing each attribute.
    def ==(o)
      return true if self.equal?(o)
      self.class == o.class &&
          phone_number == o.phone_number &&
          phone_numbe_region == o.phone_numbe_region &&
          white_list == o.white_list &&
          black_list == o.black_list &&
          quiet_hour_list == o.quiet_hour_list &&
          use_community_blacklist == o.use_community_blacklist &&
          break_through_qh_with_multiple_calls == o.break_through_qh_with_multiple_calls &&
          white_list_breaks_qh == o.white_list_breaks_qh &&
          block_behavior == o.block_behavior &&
          email == o.email &&
          age == o.age &&
          gender == o.gender &&
          salutation == o.salutation &&
          first_name == o.first_name &&
          middle_name == o.middle_name &&
          last_name == o.last_name &&
          suffix == o.suffix
    end

    # @see the `==` method
    def eql?(o)
      self == o
    end

    # Calculate hash code according to all attributes.
    def hash
      [phone_number, phone_numbe_region, white_list, black_list, quiet_hour_list, use_community_blacklist, break_through_qh_with_multiple_calls, white_list_breaks_qh, block_behavior, email, age, gender, salutation, first_name, middle_name, last_name, suffix].hash
    end

    # build the object from hash
    def build_from_hash(attributes)
      return nil unless attributes.is_a?(Hash)
      self.class.swagger_types.each_pair do |key, type|
        if type =~ /^Array<(.*)>/i
          if attributes[self.class.attribute_map[key]].is_a?(Array)
            self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
          else
            #TODO show warning in debug mode
          end
        elsif !attributes[self.class.attribute_map[key]].nil?
          self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
        else
          # data not found in attributes(hash), not an issue as the data can be optional
        end
      end

      self
    end

    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 =~ /^(true|t|yes|y|1)$/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
        _model = SwaggerClient.const_get(type).new
        _model.build_from_hash(value)
      end
    end

    def to_s
      to_hash.to_s
    end

    # to_body is an alias to to_body (backward compatibility))
    def to_body
      to_hash
    end

    # return 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

    # Method to output non-array value in the form of hash
    # For object, use to_hash. Otherwise, just return the value
    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
