##
#    This code was generated by
#    ___ _ _ _ _ _    _ ____    ____ ____ _    ____ ____ _  _ ____ ____ ____ ___ __   __
#     |  | | | | |    | |  | __ |  | |__| | __ | __ |___ |\ | |___ |__/ |__|  | |  | |__/
#     |  |_|_| | |___ | |__|    |__| |  | |    |__] |___ | \| |___ |  \ |  |  | |__| |  \
#
#    Twilio - Lookups
#    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 Lookups < LookupsBase
            class V2 < Version
                class BucketList < ListResource
                
                    class RateLimitRequest
                            # @param [limit]: [String] Limit of requests for the bucket
                            # @param [ttl]: [String] Time to live of the rule
                        attr_accessor :limit, :ttl
                        def initialize(payload)
                                @limit = payload["limit"]
                                @ttl = payload["ttl"]
                        end
                        def to_json(options = {})
                        {
                                "limit": @limit,
                                "ttl": @ttl,
                        }.to_json(options)
                        end
                    end


                    ##
                    # Initialize the BucketList
                    # @param [Version] version Version that contains the resource
                    # @return [BucketList] BucketList
                    def initialize(version)
                        super(version)
                        # Path Solution
                        @solution = {  }
                        
                        
                    end
                


                    # Provide a user friendly representation
                    def to_s
                        '#<Twilio.Lookups.V2.BucketList>'
                    end
                end


                class BucketContext < InstanceContext
                    ##
                    # Initialize the BucketContext
                    # @param [Version] version Version that contains the resource
                    # @param [String] field field name
                    # @param [String] bucket bucket name
                    # @return [BucketContext] BucketContext
                    def initialize(version, field, bucket)
                        super(version)

                        # Path Solution
                        @solution = { field: field, bucket: bucket,  }
                        @uri = "/RateLimits/Fields/#{@solution[:field]}/Bucket/#{@solution[:bucket]}"

                        
                    end
                    ##
                    # Delete the BucketInstance
                    # @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 BucketInstance
                    # @return [BucketInstance] Fetched BucketInstance
                    def fetch

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

                    ##
                    # Update the BucketInstance
                    # @param [RateLimitRequest] rate_limit_request 
                    # @return [BucketInstance] Updated BucketInstance
                    def update(rate_limit_request: :unset
                    )

                        headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', })
                        headers['Content-Type'] = 'application/json'
                        
                        
                        
                        
                        payload = @version.update('PUT', @uri, headers: headers, data: rate_limit_request.to_json)
                        BucketInstance.new(
                            @version,
                            payload,
                            field: @solution[:field],
                            bucket: @solution[:bucket],
                        )
                    end


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

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

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

                        # Path Solution
                        @solution = solution
                    end

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

                    ##
                    # Provide a user friendly representation
                    def to_s
                        '<Twilio.Lookups.V2.BucketPage>'
                    end
                end
                class BucketInstance < InstanceResource
                    ##
                    # Initialize the BucketInstance
                    # @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 Bucket
                    #   resource.
                    # @param [String] sid The SID of the Call resource to fetch.
                    # @return [BucketInstance] BucketInstance
                    def initialize(version, payload , field: nil, bucket: nil)
                        super(version)
                        
                        # Marshaled Properties
                        @properties = { 
                            'code' => payload['code'],
                            'message' => payload['message'],
                            'more_info' => payload['more_info'],
                            'status' => payload['status'],
                            'field' => payload['field'],
                            'limit' => payload['limit'],
                            'bucket' => payload['bucket'],
                            'owner' => payload['owner'],
                            'ttl' => payload['ttl'],
                        }

                        # Context
                        @instance_context = nil
                        @params = { 'field' => field  || @properties['field']  ,'bucket' => bucket  || @properties['bucket']  , }
                    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 [BucketContext] CallContext for this CallInstance
                    def context
                        unless @instance_context
                            @instance_context = BucketContext.new(@version , @params['field'], @params['bucket'])
                        end
                        @instance_context
                    end
                    
                    ##
                    # @return [String] Twilio-specific error code
                    def code
                        @properties['code']
                    end
                    
                    ##
                    # @return [String] Error message
                    def message
                        @properties['message']
                    end
                    
                    ##
                    # @return [String] Link to Error Code References
                    def more_info
                        @properties['more_info']
                    end
                    
                    ##
                    # @return [String] HTTP response status code
                    def status
                        @properties['status']
                    end
                    
                    ##
                    # @return [String] Limit of requests for the bucket
                    def field
                        @properties['field']
                    end
                    
                    ##
                    # @return [String] Limit of requests for the bucket
                    def limit
                        @properties['limit']
                    end
                    
                    ##
                    # @return [String] Name of the bucket
                    def bucket
                        @properties['bucket']
                    end
                    
                    ##
                    # @return [String] Owner of the rule
                    def owner
                        @properties['owner']
                    end
                    
                    ##
                    # @return [String] Time to live of the rule
                    def ttl
                        @properties['ttl']
                    end
                    
                    ##
                    # Delete the BucketInstance
                    # @return [Boolean] True if delete succeeds, false otherwise
                    def delete

                        context.delete
                    end

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

                        context.fetch
                    end

                    ##
                    # Update the BucketInstance
                    # @param [RateLimitRequest] rate_limit_request 
                    # @return [BucketInstance] Updated BucketInstance
                    def update(rate_limit_request: :unset
                    )

                        context.update(
                        )
                    end

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

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

            end
        end
    end
end
