##
#    This code was generated by
#    ___ _ _ _ _ _    _ ____    ____ ____ _    ____ ____ _  _ ____ ____ ____ ___ __   __
#     |  | | | | |    | |  | __ |  | |__| | __ | __ |___ |\ | |___ |__/ |__|  | |  | |__/
#     |  |_|_| | |___ | |__|    |__| |  | |    |__] |___ | \| |___ |  \ |  |  | |__| |  \
#
#    Twilio - Numbers
#    This is the public Twilio REST API.
#
#    NOTE: This class is auto generated by OpenAPI Generator.
#    https://openapi-generator.tech
#    Do not edit the class manually.
#


module Twilio
    module REST
        class Numbers < NumbersBase
            class V1 < Version
                class PortingPortabilityList < ListResource
                
                    ##
                    # Initialize the PortingPortabilityList
                    # @param [Version] version Version that contains the resource
                    # @return [PortingPortabilityList] PortingPortabilityList
                    def initialize(version)
                        super(version)
                        # Path Solution
                        @solution = {  }
                        
                        
                    end
                


                    # Provide a user friendly representation
                    def to_s
                        '#<Twilio.Numbers.V1.PortingPortabilityList>'
                    end
                end


                class PortingPortabilityContext < InstanceContext
                    ##
                    # Initialize the PortingPortabilityContext
                    # @param [Version] version Version that contains the resource
                    # @param [String] phone_number Phone number to check portability in e164 format.
                    # @return [PortingPortabilityContext] PortingPortabilityContext
                    def initialize(version, phone_number)
                        super(version)

                        # Path Solution
                        @solution = { phone_number: phone_number,  }
                        @uri = "/Porting/Portability/PhoneNumber/#{CGI.escape(@solution[:phone_number]).gsub("+", "%20")}"

                        
                    end
                    ##
                    # Fetch the PortingPortabilityInstance
                    # @param [String] target_account_sid Account Sid to which the number will be ported. This can be used to determine if a sub account already has the number in its inventory or a different sub account. If this is not provided, the authenticated account will be assumed to be the target account.
                    # @param [String] address_sid Address Sid of customer to which the number will be ported.
                    # @return [PortingPortabilityInstance] Fetched PortingPortabilityInstance
                    def fetch(
                        target_account_sid: :unset, 
                        address_sid: :unset
                    )

                        params = Twilio::Values.of({
                            'TargetAccountSid' => target_account_sid,
                            'AddressSid' => address_sid,
                        })
                        headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', })
                        
                        
                        
                        
                        
                        payload = @version.fetch('GET', @uri, params: params, headers: headers)
                        PortingPortabilityInstance.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.Numbers.V1.PortingPortabilityContext #{context}>"
                    end

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

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

                        # Path Solution
                        @solution = solution
                    end

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

                    ##
                    # Provide a user friendly representation
                    def to_s
                        '<Twilio.Numbers.V1.PortingPortabilityPage>'
                    end
                end
                class PortingPortabilityInstance < InstanceResource
                    ##
                    # Initialize the PortingPortabilityInstance
                    # @param [Version] version Version that contains the resource
                    # @param [Hash] payload payload that contains response from Twilio
                    # @param [String] account_sid The SID of the
                    #   {Account}[https://www.twilio.com/docs/iam/api/account] that created this PortingPortability
                    #   resource.
                    # @param [String] sid The SID of the Call resource to fetch.
                    # @return [PortingPortabilityInstance] PortingPortabilityInstance
                    def initialize(version, payload , phone_number: nil)
                        super(version)
                        
                        # Marshaled Properties
                        @properties = { 
                            'phone_number' => payload['phone_number'],
                            'account_sid' => payload['account_sid'],
                            'portable' => payload['portable'],
                            'pin_and_account_number_required' => payload['pin_and_account_number_required'],
                            'not_portable_reason' => payload['not_portable_reason'],
                            'not_portable_reason_code' => payload['not_portable_reason_code'] == nil ? payload['not_portable_reason_code'] : payload['not_portable_reason_code'].to_i,
                            'number_type' => payload['number_type'],
                            'country' => payload['country'],
                            '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 [PortingPortabilityContext] CallContext for this CallInstance
                    def context
                        unless @instance_context
                            @instance_context = PortingPortabilityContext.new(@version , @params['phone_number'])
                        end
                        @instance_context
                    end
                    
                    ##
                    # @return [String] The phone number which portability is to be checked. Phone numbers are in E.164 format (e.g. +16175551212).
                    def phone_number
                        @properties['phone_number']
                    end
                    
                    ##
                    # @return [String] Account Sid that the phone number belongs to in Twilio. This is only returned for phone numbers that already exist in Twilio’s inventory and belong to your account or sub account.
                    def account_sid
                        @properties['account_sid']
                    end
                    
                    ##
                    # @return [Boolean] Boolean flag indicates if the phone number can be ported into Twilio through the Porting API or not.
                    def portable
                        @properties['portable']
                    end
                    
                    ##
                    # @return [Boolean] Indicates if the port in process will require a personal identification number (PIN) and an account number for this phone number. If this is true you will be required to submit both a PIN and account number from the losing carrier for this number when opening a port in request. These fields will be required in order to complete the port in process to Twilio.
                    def pin_and_account_number_required
                        @properties['pin_and_account_number_required']
                    end
                    
                    ##
                    # @return [String] Reason why the phone number cannot be ported into Twilio, `null` otherwise.
                    def not_portable_reason
                        @properties['not_portable_reason']
                    end
                    
                    ##
                    # @return [String] The Portability Reason Code for the phone number if it cannot be ported into Twilio, `null` otherwise.
                    def not_portable_reason_code
                        @properties['not_portable_reason_code']
                    end
                    
                    ##
                    # @return [NumberType] 
                    def number_type
                        @properties['number_type']
                    end
                    
                    ##
                    # @return [String] Country the phone number belongs to.
                    def country
                        @properties['country']
                    end
                    
                    ##
                    # @return [String] This is the url of the request that you're trying to reach out to locate the resource.
                    def url
                        @properties['url']
                    end
                    
                    ##
                    # Fetch the PortingPortabilityInstance
                    # @param [String] target_account_sid Account Sid to which the number will be ported. This can be used to determine if a sub account already has the number in its inventory or a different sub account. If this is not provided, the authenticated account will be assumed to be the target account.
                    # @param [String] address_sid Address Sid of customer to which the number will be ported.
                    # @return [PortingPortabilityInstance] Fetched PortingPortabilityInstance
                    def fetch(
                        target_account_sid: :unset, 
                        address_sid: :unset
                    )

                        context.fetch(
                            target_account_sid: target_account_sid, 
                            address_sid: address_sid, 
                        )
                    end

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

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

            end
        end
    end
end
