##
#    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 V2 < Version
                class HostedNumberOrderList < ListResource
                
                    ##
                    # Initialize the HostedNumberOrderList
                    # @param [Version] version Version that contains the resource
                    # @return [HostedNumberOrderList] HostedNumberOrderList
                    def initialize(version)
                        super(version)
                        # Path Solution
                        @solution = {  }
                        @uri = "/HostedNumber/Orders"
                        
                    end
                    ##
                    # Create the HostedNumberOrderInstance
                    # @param [String] phone_number The number to host in [+E.164](https://en.wikipedia.org/wiki/E.164) format
                    # @param [String] contact_phone_number The contact phone number of the person authorized to sign the Authorization Document.
                    # @param [String] address_sid Optional. A 34 character string that uniquely identifies the Address resource that represents the address of the owner of this phone number.
                    # @param [String] email Optional. Email of the owner of this phone number that is being hosted.
                    # @param [String] account_sid This defaults to the AccountSid of the authorization the user is using. This can be provided to specify a subaccount to add the HostedNumberOrder to.
                    # @param [String] friendly_name A 128 character string that is a human readable text that describes this resource.
                    # @param [Array[String]] cc_emails Optional. A list of emails that the LOA document for this HostedNumberOrder will be carbon copied to.
                    # @param [String] sms_url The URL that Twilio should request when somebody sends an SMS to the phone number. This will be copied onto the IncomingPhoneNumber resource.
                    # @param [String] sms_method The HTTP method that should be used to request the SmsUrl. Must be either `GET` or `POST`.  This will be copied onto the IncomingPhoneNumber resource.
                    # @param [String] sms_fallback_url A URL that Twilio will request if an error occurs requesting or executing the TwiML defined by SmsUrl. This will be copied onto the IncomingPhoneNumber resource.
                    # @param [Boolean] sms_capability Used to specify that the SMS capability will be hosted on Twilio's platform.
                    # @param [String] sms_fallback_method The HTTP method that should be used to request the SmsFallbackUrl. Must be either `GET` or `POST`. This will be copied onto the IncomingPhoneNumber resource.
                    # @param [String] status_callback_url Optional. The Status Callback URL attached to the IncomingPhoneNumber resource.
                    # @param [String] status_callback_method Optional. The Status Callback Method attached to the IncomingPhoneNumber resource.
                    # @param [String] sms_application_sid Optional. The 34 character sid of the application Twilio should use to handle SMS messages sent to this number. If a `SmsApplicationSid` is present, Twilio will ignore all of the SMS urls above and use those set on the application.
                    # @param [String] contact_title The title of the person authorized to sign the Authorization Document for this phone number.
                    # @return [HostedNumberOrderInstance] Created HostedNumberOrderInstance
                    def create(
                        phone_number: nil, 
                        contact_phone_number: nil, 
                        address_sid: nil, 
                        email: nil, 
                        account_sid: :unset, 
                        friendly_name: :unset, 
                        cc_emails: :unset, 
                        sms_url: :unset, 
                        sms_method: :unset, 
                        sms_fallback_url: :unset, 
                        sms_capability: :unset, 
                        sms_fallback_method: :unset, 
                        status_callback_url: :unset, 
                        status_callback_method: :unset, 
                        sms_application_sid: :unset, 
                        contact_title: :unset
                    )

                        data = Twilio::Values.of({
                            'PhoneNumber' => phone_number,
                            'ContactPhoneNumber' => contact_phone_number,
                            'AddressSid' => address_sid,
                            'Email' => email,
                            'AccountSid' => account_sid,
                            'FriendlyName' => friendly_name,
                            'CcEmails' => Twilio.serialize_list(cc_emails) { |e| e },
                            'SmsUrl' => sms_url,
                            'SmsMethod' => sms_method,
                            'SmsFallbackUrl' => sms_fallback_url,
                            'SmsCapability' => sms_capability,
                            'SmsFallbackMethod' => sms_fallback_method,
                            'StatusCallbackUrl' => status_callback_url,
                            'StatusCallbackMethod' => status_callback_method,
                            'SmsApplicationSid' => sms_application_sid,
                            'ContactTitle' => contact_title,
                        })

                        headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', })
                        
                        
                        
                        
                        
                        payload = @version.create('POST', @uri, data: data, headers: headers)
                        HostedNumberOrderInstance.new(
                            @version,
                            payload,
                        )
                    end

                
                    ##
                    # Lists HostedNumberOrderInstance records from the API as a list.
                    # Unlike stream(), this operation is eager and will load `limit` records into
                    # memory before returning.
                    # @param [Status] status The Status of this HostedNumberOrder. One of `received`, `pending-verification`, `verified`, `pending-loa`, `carrier-processing`, `testing`, `completed`, `failed`, or `action-required`.
                    # @param [Boolean] sms_capability Whether the SMS capability will be hosted on our platform. Can be `true` of `false`.
                    # @param [String] phone_number An E164 formatted phone number hosted by this HostedNumberOrder.
                    # @param [String] incoming_phone_number_sid A 34 character string that uniquely identifies the IncomingPhoneNumber resource created by this HostedNumberOrder.
                    # @param [String] friendly_name A human readable description of this resource, up to 128 characters.
                    # @param [Integer] limit Upper limit for the number of records to return. stream()
                    #    guarantees to never return more than limit.  Default is no limit
                    # @param [Integer] page_size Number of records to fetch per request, when
                    #    not set will use the default value of 50 records.  If no page_size is defined
                    #    but a limit is defined, stream() will attempt to read the limit with the most
                    #    efficient page size, i.e. min(limit, 1000)
                    # @return [Array] Array of up to limit results
                    def list(status: :unset, sms_capability: :unset, phone_number: :unset, incoming_phone_number_sid: :unset, friendly_name: :unset, limit: nil, page_size: nil)
                        self.stream(
                            status: status,
                            sms_capability: sms_capability,
                            phone_number: phone_number,
                            incoming_phone_number_sid: incoming_phone_number_sid,
                            friendly_name: friendly_name,
                            limit: limit,
                            page_size: page_size
                        ).entries
                    end

                    ##
                    # Streams Instance records from the API as an Enumerable.
                    # This operation lazily loads records as efficiently as possible until the limit
                    # is reached.
                    # @param [Status] status The Status of this HostedNumberOrder. One of `received`, `pending-verification`, `verified`, `pending-loa`, `carrier-processing`, `testing`, `completed`, `failed`, or `action-required`.
                    # @param [Boolean] sms_capability Whether the SMS capability will be hosted on our platform. Can be `true` of `false`.
                    # @param [String] phone_number An E164 formatted phone number hosted by this HostedNumberOrder.
                    # @param [String] incoming_phone_number_sid A 34 character string that uniquely identifies the IncomingPhoneNumber resource created by this HostedNumberOrder.
                    # @param [String] friendly_name A human readable description of this resource, up to 128 characters.
                    # @param [Integer] limit Upper limit for the number of records to return. stream()
                    #    guarantees to never return more than limit.  Default is no limit
                    # @param [Integer] page_size Number of records to fetch per request, when
                    #    not set will use the default value of 50 records.  If no page_size is defined
                    #    but a limit is defined, stream() will attempt to read the limit with the most
                    #    efficient page size, i.e. min(limit, 1000)
                    # @return [Enumerable] Enumerable that will yield up to limit results
                    def stream(status: :unset, sms_capability: :unset, phone_number: :unset, incoming_phone_number_sid: :unset, friendly_name: :unset, limit: nil, page_size: nil)
                        limits = @version.read_limits(limit, page_size)

                        page = self.page(
                            status: status,
                            sms_capability: sms_capability,
                            phone_number: phone_number,
                            incoming_phone_number_sid: incoming_phone_number_sid,
                            friendly_name: friendly_name,
                            page_size: limits[:page_size], )

                        @version.stream(page, limit: limits[:limit], page_limit: limits[:page_limit])
                    end

                    ##
                    # When passed a block, yields HostedNumberOrderInstance records from the API.
                    # This operation lazily loads records as efficiently as possible until the limit
                    # is reached.
                    def each
                        limits = @version.read_limits

                        page = self.page(page_size: limits[:page_size], )

                        @version.stream(page,
                            limit: limits[:limit],
                            page_limit: limits[:page_limit]).each {|x| yield x}
                    end

                    ##
                    # Retrieve a single page of HostedNumberOrderInstance records from the API.
                    # Request is executed immediately.
                    # @param [Status] status The Status of this HostedNumberOrder. One of `received`, `pending-verification`, `verified`, `pending-loa`, `carrier-processing`, `testing`, `completed`, `failed`, or `action-required`.
                    # @param [Boolean] sms_capability Whether the SMS capability will be hosted on our platform. Can be `true` of `false`.
                    # @param [String] phone_number An E164 formatted phone number hosted by this HostedNumberOrder.
                    # @param [String] incoming_phone_number_sid A 34 character string that uniquely identifies the IncomingPhoneNumber resource created by this HostedNumberOrder.
                    # @param [String] friendly_name A human readable description of this resource, up to 128 characters.
                    # @param [String] page_token PageToken provided by the API
                    # @param [Integer] page_number Page Number, this value is simply for client state
                    # @param [Integer] page_size Number of records to return, defaults to 50
                    # @return [Page] Page of HostedNumberOrderInstance
                    def page(status: :unset, sms_capability: :unset, phone_number: :unset, incoming_phone_number_sid: :unset, friendly_name: :unset, page_token: :unset, page_number: :unset, page_size: :unset)
                        params = Twilio::Values.of({
                            'Status' => status,
                            'SmsCapability' => sms_capability,
                            'PhoneNumber' => phone_number,
                            'IncomingPhoneNumberSid' => incoming_phone_number_sid,
                            'FriendlyName' => friendly_name,
                            'PageToken' => page_token,
                            'Page' => page_number,
                            'PageSize' => page_size,
                        })
                        headers = Twilio::Values.of({})
                        
                        

                        response = @version.page('GET', @uri, params: params, headers: headers)

                        HostedNumberOrderPage.new(@version, response, @solution)
                    end

                    ##
                    # Retrieve a single page of HostedNumberOrderInstance records from the API.
                    # Request is executed immediately.
                    # @param [String] target_url API-generated URL for the requested results page
                    # @return [Page] Page of HostedNumberOrderInstance
                    def get_page(target_url)
                        response = @version.domain.request(
                            'GET',
                            target_url
                        )
                    HostedNumberOrderPage.new(@version, response, @solution)
                    end
                    


                    # Provide a user friendly representation
                    def to_s
                        '#<Twilio.Numbers.V2.HostedNumberOrderList>'
                    end
                end


                class HostedNumberOrderContext < InstanceContext
                    ##
                    # Initialize the HostedNumberOrderContext
                    # @param [Version] version Version that contains the resource
                    # @param [String] sid The SID of the HostedNumberOrder resource to update.
                    # @return [HostedNumberOrderContext] HostedNumberOrderContext
                    def initialize(version, sid)
                        super(version)

                        # Path Solution
                        @solution = { sid: sid,  }
                        @uri = "/HostedNumber/Orders/#{@solution[:sid]}"

                        
                    end
                    ##
                    # Delete the HostedNumberOrderInstance
                    # @return [Boolean] True if delete succeeds, false otherwise
                    def delete

                        headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', })
                        
                        
                        
                        @version.delete('DELETE', @uri, headers: headers)
                    end

                    ##
                    # Fetch the HostedNumberOrderInstance
                    # @return [HostedNumberOrderInstance] Fetched HostedNumberOrderInstance
                    def fetch

                        headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', })
                        
                        
                        
                        
                        
                        payload = @version.fetch('GET', @uri, headers: headers)
                        HostedNumberOrderInstance.new(
                            @version,
                            payload,
                            sid: @solution[:sid],
                        )
                    end

                    ##
                    # Update the HostedNumberOrderInstance
                    # @param [Status] status 
                    # @param [String] verification_call_delay The number of seconds to wait before initiating the ownership verification call. Can be a value between 0 and 60, inclusive.
                    # @param [String] verification_call_extension The numerical extension to dial when making the ownership verification call.
                    # @return [HostedNumberOrderInstance] Updated HostedNumberOrderInstance
                    def update(
                        status: nil, 
                        verification_call_delay: :unset, 
                        verification_call_extension: :unset
                    )

                        data = Twilio::Values.of({
                            'Status' => status,
                            'VerificationCallDelay' => verification_call_delay,
                            'VerificationCallExtension' => verification_call_extension,
                        })

                        headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', })
                        
                        
                        
                        
                        
                        payload = @version.update('POST', @uri, data: data, headers: headers)
                        HostedNumberOrderInstance.new(
                            @version,
                            payload,
                            sid: @solution[:sid],
                        )
                    end


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

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

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

                        # Path Solution
                        @solution = solution
                    end

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

                    ##
                    # Provide a user friendly representation
                    def to_s
                        '<Twilio.Numbers.V2.HostedNumberOrderPage>'
                    end
                end
                class HostedNumberOrderInstance < InstanceResource
                    ##
                    # Initialize the HostedNumberOrderInstance
                    # @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 HostedNumberOrder
                    #   resource.
                    # @param [String] sid The SID of the Call resource to fetch.
                    # @return [HostedNumberOrderInstance] HostedNumberOrderInstance
                    def initialize(version, payload , sid: nil)
                        super(version)
                        
                        # Marshaled Properties
                        @properties = { 
                            'sid' => payload['sid'],
                            'account_sid' => payload['account_sid'],
                            'incoming_phone_number_sid' => payload['incoming_phone_number_sid'],
                            'address_sid' => payload['address_sid'],
                            'signing_document_sid' => payload['signing_document_sid'],
                            'phone_number' => payload['phone_number'],
                            'capabilities' => payload['capabilities'],
                            'friendly_name' => payload['friendly_name'],
                            'status' => payload['status'],
                            'failure_reason' => payload['failure_reason'],
                            'date_created' => Twilio.deserialize_iso8601_datetime(payload['date_created']),
                            'date_updated' => Twilio.deserialize_iso8601_datetime(payload['date_updated']),
                            'email' => payload['email'],
                            'cc_emails' => payload['cc_emails'],
                            'url' => payload['url'],
                            'contact_title' => payload['contact_title'],
                            'contact_phone_number' => payload['contact_phone_number'],
                            'bulk_hosting_request_sid' => payload['bulk_hosting_request_sid'],
                            'next_step' => payload['next_step'],
                            'verification_attempts' => payload['verification_attempts'] == nil ? payload['verification_attempts'] : payload['verification_attempts'].to_i,
                            'verification_call_sids' => payload['verification_call_sids'],
                            'verification_call_delay' => payload['verification_call_delay'] == nil ? payload['verification_call_delay'] : payload['verification_call_delay'].to_i,
                            'verification_call_extension' => payload['verification_call_extension'],
                            'verification_code' => payload['verification_code'],
                            'verification_type' => payload['verification_type'],
                        }

                        # Context
                        @instance_context = nil
                        @params = { 'sid' => sid  || @properties['sid']  , }
                    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 [HostedNumberOrderContext] CallContext for this CallInstance
                    def context
                        unless @instance_context
                            @instance_context = HostedNumberOrderContext.new(@version , @params['sid'])
                        end
                        @instance_context
                    end
                    
                    ##
                    # @return [String] A 34 character string that uniquely identifies this HostedNumberOrder.
                    def sid
                        @properties['sid']
                    end
                    
                    ##
                    # @return [String] A 34 character string that uniquely identifies the account.
                    def account_sid
                        @properties['account_sid']
                    end
                    
                    ##
                    # @return [String] A 34 character string that uniquely identifies the [IncomingPhoneNumber](https://www.twilio.com/docs/phone-numbers/api/incomingphonenumber-resource) resource that represents the phone number being hosted.
                    def incoming_phone_number_sid
                        @properties['incoming_phone_number_sid']
                    end
                    
                    ##
                    # @return [String] A 34 character string that uniquely identifies the Address resource that represents the address of the owner of this phone number.
                    def address_sid
                        @properties['address_sid']
                    end
                    
                    ##
                    # @return [String] A 34 character string that uniquely identifies the [Authorization Document](https://www.twilio.com/docs/phone-numbers/hosted-numbers/hosted-numbers-api/authorization-document-resource) the user needs to sign.
                    def signing_document_sid
                        @properties['signing_document_sid']
                    end
                    
                    ##
                    # @return [String] Phone number to be hosted. This must be in [E.164](https://en.wikipedia.org/wiki/E.164) format, e.g., +16175551212
                    def phone_number
                        @properties['phone_number']
                    end
                    
                    ##
                    # @return [NumbersV2HostedNumberOrderCapabilities] 
                    def capabilities
                        @properties['capabilities']
                    end
                    
                    ##
                    # @return [String] A 128 character string that is a human-readable text that describes this resource.
                    def friendly_name
                        @properties['friendly_name']
                    end
                    
                    ##
                    # @return [Status] 
                    def status
                        @properties['status']
                    end
                    
                    ##
                    # @return [String] A message that explains why a hosted_number_order went to status \"action-required\"
                    def failure_reason
                        @properties['failure_reason']
                    end
                    
                    ##
                    # @return [Time] The date this resource was created, given as [GMT RFC 2822](http://www.ietf.org/rfc/rfc2822.txt) format.
                    def date_created
                        @properties['date_created']
                    end
                    
                    ##
                    # @return [Time] The date that this resource was updated, given as [GMT RFC 2822](http://www.ietf.org/rfc/rfc2822.txt) format.
                    def date_updated
                        @properties['date_updated']
                    end
                    
                    ##
                    # @return [String] Email of the owner of this phone number that is being hosted.
                    def email
                        @properties['email']
                    end
                    
                    ##
                    # @return [Array<String>] A list of emails that LOA document for this HostedNumberOrder will be carbon copied to.
                    def cc_emails
                        @properties['cc_emails']
                    end
                    
                    ##
                    # @return [String] The URL of this HostedNumberOrder.
                    def url
                        @properties['url']
                    end
                    
                    ##
                    # @return [String] The title of the person authorized to sign the Authorization Document for this phone number.
                    def contact_title
                        @properties['contact_title']
                    end
                    
                    ##
                    # @return [String] The contact phone number of the person authorized to sign the Authorization Document.
                    def contact_phone_number
                        @properties['contact_phone_number']
                    end
                    
                    ##
                    # @return [String] A 34 character string that uniquely identifies the bulk hosting request associated with this HostedNumberOrder.
                    def bulk_hosting_request_sid
                        @properties['bulk_hosting_request_sid']
                    end
                    
                    ##
                    # @return [String] The next step you need to take to complete the hosted number order and request it successfully.
                    def next_step
                        @properties['next_step']
                    end
                    
                    ##
                    # @return [String] The number of attempts made to verify ownership via a call for the hosted phone number.
                    def verification_attempts
                        @properties['verification_attempts']
                    end
                    
                    ##
                    # @return [Array<String>] The Call SIDs that identify the calls placed to verify ownership.
                    def verification_call_sids
                        @properties['verification_call_sids']
                    end
                    
                    ##
                    # @return [String] The number of seconds to wait before initiating the ownership verification call. Can be a value between 0 and 60, inclusive.
                    def verification_call_delay
                        @properties['verification_call_delay']
                    end
                    
                    ##
                    # @return [String] The numerical extension to dial when making the ownership verification call.
                    def verification_call_extension
                        @properties['verification_call_extension']
                    end
                    
                    ##
                    # @return [String] The digits the user must pass in the ownership verification call.
                    def verification_code
                        @properties['verification_code']
                    end
                    
                    ##
                    # @return [VerificationType] 
                    def verification_type
                        @properties['verification_type']
                    end
                    
                    ##
                    # Delete the HostedNumberOrderInstance
                    # @return [Boolean] True if delete succeeds, false otherwise
                    def delete

                        context.delete
                    end

                    ##
                    # Fetch the HostedNumberOrderInstance
                    # @return [HostedNumberOrderInstance] Fetched HostedNumberOrderInstance
                    def fetch

                        context.fetch
                    end

                    ##
                    # Update the HostedNumberOrderInstance
                    # @param [Status] status 
                    # @param [String] verification_call_delay The number of seconds to wait before initiating the ownership verification call. Can be a value between 0 and 60, inclusive.
                    # @param [String] verification_call_extension The numerical extension to dial when making the ownership verification call.
                    # @return [HostedNumberOrderInstance] Updated HostedNumberOrderInstance
                    def update(
                        status: nil, 
                        verification_call_delay: :unset, 
                        verification_call_extension: :unset
                    )

                        context.update(
                            status: status, 
                            verification_call_delay: verification_call_delay, 
                            verification_call_extension: verification_call_extension, 
                        )
                    end

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

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

            end
        end
    end
end
