##
# This code was generated by
# \ / _    _  _|   _  _
#  | (_)\/(_)(_|\/| |(/_  v1.0.0
#       /       /
# 
# frozen_string_literal: true

module Twilio
  module REST
    class Lookups < Domain
      class V1 < Version
        class PhoneNumberList < ListResource
          ##
          # Initialize the PhoneNumberList
          # @param [Version] version Version that contains the resource
          # @return [PhoneNumberList] PhoneNumberList
          def initialize(version)
            super(version)

            # Path Solution
            @solution = {}
          end

          ##
          # Provide a user friendly representation
          def to_s
            '#<Twilio.Lookups.V1.PhoneNumberList>'
          end
        end

        class PhoneNumberPage < Page
          ##
          # Initialize the PhoneNumberPage
          # @param [Version] version Version that contains the resource
          # @param [Response] response Response from the API
          # @param [Hash] solution Path solution for the resource
          # @return [PhoneNumberPage] PhoneNumberPage
          def initialize(version, response, solution)
            super(version, response)

            # Path Solution
            @solution = solution
          end

          ##
          # Build an instance of PhoneNumberInstance
          # @param [Hash] payload Payload response from the API
          # @return [PhoneNumberInstance] PhoneNumberInstance
          def get_instance(payload)
            PhoneNumberInstance.new(@version, payload, )
          end

          ##
          # Provide a user friendly representation
          def to_s
            '<Twilio.Lookups.V1.PhoneNumberPage>'
          end
        end

        class PhoneNumberContext < InstanceContext
          ##
          # Initialize the PhoneNumberContext
          # @param [Version] version Version that contains the resource
          # @param [String] phone_number The phone_number
          # @return [PhoneNumberContext] PhoneNumberContext
          def initialize(version, phone_number)
            super(version)

            # Path Solution
            @solution = {phone_number: phone_number, }
            @uri = "/PhoneNumbers/#{@solution[:phone_number]}"
          end

          ##
          # Fetch a PhoneNumberInstance
          # @param [String] country_code Optional [ISO country
          #   code](http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) of the phone number. This
          #   is used to specify the country when the number is provided in a national format.
          # @param [String] type Indicates the type of information you would like returned
          #   with your request. Possible values are `carrier` or `caller-name`. If not
          #   specified, the default is null.  Carrier information costs $0.005 per phone
          #   number looked up.  Caller Name information costs $0.01 per phone number looked
          #   up, and is currently ONLY available in the US.  You can retrieve both types of
          #   information by including two `Type` arguments or making two separate requests.
          # @param [String] add_ons Indicates the particular Add-on you would like to use to
          #   get more information. Possible values are the *Add-on Unique Names* of Add-ons
          #   installed on your account. You can specify multiple instances of this parameter
          #   to invoke different Add-ons. See [Add-ons
          #   documentation](https://www.twilio.com/docs/api/addons) for information on
          #   installing Add-ons. Add-on pricing is available in your list of Installed
          #   Add-ons in the Console.
          # @param [Hash] add_ons_data The add_ons_data
          # @return [PhoneNumberInstance] Fetched PhoneNumberInstance
          def fetch(country_code: :unset, type: :unset, add_ons: :unset, add_ons_data: :unset)
            params = Twilio::Values.of({
                'CountryCode' => country_code,
                'Type' => Twilio.serialize_list(type) { |e| e },
                'AddOns' => Twilio.serialize_list(add_ons) { |e| e },
            })

            params.merge!(Twilio.prefixed_collapsible_map(add_ons_data, 'AddOns'))
            payload = @version.fetch(
                'GET',
                @uri,
                params,
            )

            PhoneNumberInstance.new(@version, payload, phone_number: @solution[:phone_number], )
          end

          ##
          # Provide a user friendly representation
          def to_s
            context = @solution.map {|k, v| "#{k}: #{v}"}.join(',')
            "#<Twilio.Lookups.V1.PhoneNumberContext #{context}>"
          end

          ##
          # Provide a detailed, user friendly representation
          def inspect
            context = @solution.map {|k, v| "#{k}: #{v}"}.join(',')
            "#<Twilio.Lookups.V1.PhoneNumberContext #{context}>"
          end
        end

        class PhoneNumberInstance < InstanceResource
          ##
          # Initialize the PhoneNumberInstance
          # @param [Version] version Version that contains the resource
          # @param [Hash] payload payload that contains response from Twilio
          # @param [String] phone_number The phone_number
          # @return [PhoneNumberInstance] PhoneNumberInstance
          def initialize(version, payload, phone_number: nil)
            super(version)

            # Marshaled Properties
            @properties = {
                'caller_name' => payload['caller_name'],
                'country_code' => payload['country_code'],
                'phone_number' => payload['phone_number'],
                'national_format' => payload['national_format'],
                'carrier' => payload['carrier'],
                'add_ons' => payload['add_ons'],
                'url' => payload['url'],
            }

            # Context
            @instance_context = nil
            @params = {'phone_number' => phone_number || @properties['phone_number'], }
          end

          ##
          # Generate an instance context for the instance, the context is capable of
          # performing various actions.  All instance actions are proxied to the context
          # @return [PhoneNumberContext] PhoneNumberContext for this PhoneNumberInstance
          def context
            unless @instance_context
              @instance_context = PhoneNumberContext.new(@version, @params['phone_number'], )
            end
            @instance_context
          end

          ##
          # @return [String] String indicating the name of the owner of the phone number.
          def caller_name
            @properties['caller_name']
          end

          ##
          # @return [String] The ISO country code for the phone number.
          def country_code
            @properties['country_code']
          end

          ##
          # @return [String] The phone number, in E.
          def phone_number
            @properties['phone_number']
          end

          ##
          # @return [String] The phone number, in national format.
          def national_format
            @properties['national_format']
          end

          ##
          # @return [String] The carrier
          def carrier
            @properties['carrier']
          end

          ##
          # @return [Hash] Results of any Add-ons you have specified using the AddOn parameter in the request, as a JSON dictionary.
          def add_ons
            @properties['add_ons']
          end

          ##
          # @return [String] The url
          def url
            @properties['url']
          end

          ##
          # Fetch a PhoneNumberInstance
          # @param [String] country_code Optional [ISO country
          #   code](http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) of the phone number. This
          #   is used to specify the country when the number is provided in a national format.
          # @param [String] type Indicates the type of information you would like returned
          #   with your request. Possible values are `carrier` or `caller-name`. If not
          #   specified, the default is null.  Carrier information costs $0.005 per phone
          #   number looked up.  Caller Name information costs $0.01 per phone number looked
          #   up, and is currently ONLY available in the US.  You can retrieve both types of
          #   information by including two `Type` arguments or making two separate requests.
          # @param [String] add_ons Indicates the particular Add-on you would like to use to
          #   get more information. Possible values are the *Add-on Unique Names* of Add-ons
          #   installed on your account. You can specify multiple instances of this parameter
          #   to invoke different Add-ons. See [Add-ons
          #   documentation](https://www.twilio.com/docs/api/addons) for information on
          #   installing Add-ons. Add-on pricing is available in your list of Installed
          #   Add-ons in the Console.
          # @param [Hash] add_ons_data The add_ons_data
          # @return [PhoneNumberInstance] Fetched PhoneNumberInstance
          def fetch(country_code: :unset, type: :unset, add_ons: :unset, add_ons_data: :unset)
            context.fetch(country_code: country_code, type: type, add_ons: add_ons, add_ons_data: add_ons_data, )
          end

          ##
          # Provide a user friendly representation
          def to_s
            values = @params.map{|k, v| "#{k}: #{v}"}.join(" ")
            "<Twilio.Lookups.V1.PhoneNumberInstance #{values}>"
          end

          ##
          # Provide a detailed, user friendly representation
          def inspect
            values = @properties.map{|k, v| "#{k}: #{v}"}.join(" ")
            "<Twilio.Lookups.V1.PhoneNumberInstance #{values}>"
          end
        end
      end
    end
  end
end