##
#    This code was generated by
#    ___ _ _ _ _ _    _ ____    ____ ____ _    ____ ____ _  _ ____ ____ ____ ___ __   __
#     |  | | | | |    | |  | __ |  | |__| | __ | __ |___ |\ | |___ |__/ |__|  | |  | |__/
#     |  |_|_| | |___ | |__|    |__| |  | |    |__] |___ | \| |___ |  \ |  |  | |__| |  \
#
#    Twilio - Api
#    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 Api < ApiBase
            class V2010 < Version
                class AccountContext < InstanceContext
                class CallContext < InstanceContext

                     class UserDefinedMessageSubscriptionList < ListResource
                
                    ##
                    # Initialize the UserDefinedMessageSubscriptionList
                    # @param [Version] version Version that contains the resource
                    # @return [UserDefinedMessageSubscriptionList] UserDefinedMessageSubscriptionList
                    def initialize(version, account_sid: nil, call_sid: nil)
                        super(version)
                        # Path Solution
                        @solution = { account_sid: account_sid, call_sid: call_sid }
                        @uri = "/Accounts/#{@solution[:account_sid]}/Calls/#{@solution[:call_sid]}/UserDefinedMessageSubscriptions.json"
                        
                    end
                    ##
                    # Create the UserDefinedMessageSubscriptionInstance
                    # @param [String] callback The URL we should call using the `method` to send user defined events to your application. URLs must contain a valid hostname (underscores are not permitted).
                    # @param [String] idempotency_key A unique string value to identify API call. This should be a unique string value per API call and can be a randomly generated.
                    # @param [String] method The HTTP method Twilio will use when requesting the above `Url`. Either `GET` or `POST`. Default is `POST`.
                    # @return [UserDefinedMessageSubscriptionInstance] Created UserDefinedMessageSubscriptionInstance
                    def create(
                        callback: nil, 
                        idempotency_key: :unset, 
                        method: :unset
                    )

                        data = Twilio::Values.of({
                            'Callback' => callback,
                            'IdempotencyKey' => idempotency_key,
                            'Method' => method,
                        })

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

                


                    # Provide a user friendly representation
                    def to_s
                        '#<Twilio.Api.V2010.UserDefinedMessageSubscriptionList>'
                    end
                end


                class UserDefinedMessageSubscriptionContext < InstanceContext
                    ##
                    # Initialize the UserDefinedMessageSubscriptionContext
                    # @param [Version] version Version that contains the resource
                    # @param [String] account_sid The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that subscribed to the User Defined Messages.
                    # @param [String] call_sid The SID of the [Call](https://www.twilio.com/docs/voice/api/call-resource) the User Defined Message Subscription is associated with. This refers to the Call SID that is producing the User Defined Messages.
                    # @param [String] sid The SID that uniquely identifies this User Defined Message Subscription.
                    # @return [UserDefinedMessageSubscriptionContext] UserDefinedMessageSubscriptionContext
                    def initialize(version, account_sid, call_sid, sid)
                        super(version)

                        # Path Solution
                        @solution = { account_sid: account_sid, call_sid: call_sid, sid: sid,  }
                        @uri = "/Accounts/#{@solution[:account_sid]}/Calls/#{@solution[:call_sid]}/UserDefinedMessageSubscriptions/#{@solution[:sid]}.json"

                        
                    end
                    ##
                    # Delete the UserDefinedMessageSubscriptionInstance
                    # @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


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

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

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

                        # Path Solution
                        @solution = solution
                    end

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

                    ##
                    # Provide a user friendly representation
                    def to_s
                        '<Twilio.Api.V2010.UserDefinedMessageSubscriptionPage>'
                    end
                end
                class UserDefinedMessageSubscriptionInstance < InstanceResource
                    ##
                    # Initialize the UserDefinedMessageSubscriptionInstance
                    # @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 UserDefinedMessageSubscription
                    #   resource.
                    # @param [String] sid The SID of the Call resource to fetch.
                    # @return [UserDefinedMessageSubscriptionInstance] UserDefinedMessageSubscriptionInstance
                    def initialize(version, payload , account_sid: nil, call_sid: nil, sid: nil)
                        super(version)
                        
                        # Marshaled Properties
                        @properties = { 
                            'account_sid' => payload['account_sid'],
                            'call_sid' => payload['call_sid'],
                            'sid' => payload['sid'],
                            'date_created' => Twilio.deserialize_rfc2822(payload['date_created']),
                            'uri' => payload['uri'],
                        }

                        # Context
                        @instance_context = nil
                        @params = { 'account_sid' => account_sid  ,'call_sid' => call_sid  || @properties['call_sid']  ,'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 [UserDefinedMessageSubscriptionContext] CallContext for this CallInstance
                    def context
                        unless @instance_context
                            @instance_context = UserDefinedMessageSubscriptionContext.new(@version , @params['account_sid'], @params['call_sid'], @params['sid'])
                        end
                        @instance_context
                    end
                    
                    ##
                    # @return [String] The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that subscribed to the User Defined Messages.
                    def account_sid
                        @properties['account_sid']
                    end
                    
                    ##
                    # @return [String] The SID of the [Call](https://www.twilio.com/docs/voice/api/call-resource) the User Defined Message Subscription is associated with. This refers to the Call SID that is producing the User Defined Messages.
                    def call_sid
                        @properties['call_sid']
                    end
                    
                    ##
                    # @return [String] The SID that uniquely identifies this User Defined Message Subscription.
                    def sid
                        @properties['sid']
                    end
                    
                    ##
                    # @return [Time] The date that this User Defined Message Subscription was created, given in RFC 2822 format.
                    def date_created
                        @properties['date_created']
                    end
                    
                    ##
                    # @return [String] The URI of the User Defined Message Subscription Resource, relative to `https://api.twilio.com`.
                    def uri
                        @properties['uri']
                    end
                    
                    ##
                    # Delete the UserDefinedMessageSubscriptionInstance
                    # @return [Boolean] True if delete succeeds, false otherwise
                    def delete

                        context.delete
                    end

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

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

             end
             end
            end
        end
    end
end


