##
#    This code was generated by
#    ___ _ _ _ _ _    _ ____    ____ ____ _    ____ ____ _  _ ____ ____ ____ ___ __   __
#     |  | | | | |    | |  | __ |  | |__| | __ | __ |___ |\ | |___ |__/ |__|  | |  | |__/
#     |  |_|_| | |___ | |__|    |__| |  | |    |__] |___ | \| |___ |  \ |  |  | |__| |  \
#
#    Organization Public API
#    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
#
#    NOTE: This class is auto generated by OpenAPI Generator.
#    https://openapi-generator.tech
#    Do not edit the class manually.
#


module Twilio
    module REST
        class PreviewIam < PreviewIamBase
            class Versionless < Version
                class OrganizationContext < InstanceContext

                     class RoleAssignmentList < ListResource
                
                    class PublicApiCreateRoleAssignmentRequest
                            # @param [role_sid]: [String] Twilio Role Sid representing assigned role
                            # @param [scope]: [String] Twilio Sid representing scope of this assignment
                            # @param [identity]: [String] Twilio Sid representing identity of this assignment
                        attr_accessor :role_sid, :scope, :identity
                        def initialize(payload)
                                @role_sid = payload["role_sid"]
                                @scope = payload["scope"]
                                @identity = payload["identity"]
                        end
                        def to_json(options = {})
                        {
                                "role_sid": @role_sid,
                                "scope": @scope,
                                "identity": @identity,
                        }.to_json(options)
                        end
                    end


                    ##
                    # Initialize the RoleAssignmentList
                    # @param [Version] version Version that contains the resource
                    # @return [RoleAssignmentList] RoleAssignmentList
                    def initialize(version, organization_sid: nil)
                        super(version)
                        # Path Solution
                        @solution = { organization_sid: organization_sid }
                        @uri = "/#{@solution[:organization_sid]}/RoleAssignments"
                        
                    end
                    ##
                    # Create the RoleAssignmentInstance
                    # @param [PublicApiCreateRoleAssignmentRequest] public_api_create_role_assignment_request 
                    # @return [RoleAssignmentInstance] Created RoleAssignmentInstance
                    def create(public_api_create_role_assignment_request: nil
                    )

                        headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', })
                        headers['Content-Type'] = 'application/json'
                        
                        
                        
                         headers['Accept'] = '*/*'
                        payload = @version.create('POST', @uri, headers: headers, data: public_api_create_role_assignment_request.to_json)
                        RoleAssignmentInstance.new(
                            @version,
                            payload,
                            organization_sid: @solution[:organization_sid],
                        )
                    end

                
                    ##
                    # Lists RoleAssignmentInstance records from the API as a list.
                    # Unlike stream(), this operation is eager and will load `limit` records into
                    # memory before returning.
                    # @param [String] identity 
                    # @param [String] scope 
                    # @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(identity: :unset, scope: :unset, limit: nil, page_size: nil)
                        self.stream(
                            identity: identity,
                            scope: scope,
                            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 [String] identity 
                    # @param [String] scope 
                    # @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(identity: :unset, scope: :unset, limit: nil, page_size: nil)
                        limits = @version.read_limits(limit, page_size)

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

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

                    ##
                    # When passed a block, yields RoleAssignmentInstance 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 RoleAssignmentInstance records from the API.
                    # Request is executed immediately.
                    # @param [String] identity 
                    # @param [String] scope 
                    # @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 RoleAssignmentInstance
                    def page(identity: :unset, scope: :unset, page_token: :unset, page_number: :unset, page_size: :unset)
                        params = Twilio::Values.of({
                            'Identity' => identity,
                            'Scope' => scope,
                            'PageToken' => page_token,
                            'Page' => page_number,
                            'PageSize' => page_size,
                        })
                        headers = Twilio::Values.of({})
                        
                        

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

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

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


                    # Provide a user friendly representation
                    def to_s
                        '#<Twilio.PreviewIam.Versionless.RoleAssignmentList>'
                    end
                end


                class RoleAssignmentContext < InstanceContext
                    ##
                    # Initialize the RoleAssignmentContext
                    # @param [Version] version Version that contains the resource
                    # @param [String] organization_sid 
                    # @param [String] sid 
                    # @return [RoleAssignmentContext] RoleAssignmentContext
                    def initialize(version, organization_sid, sid)
                        super(version)

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

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

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


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

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

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

                        # Path Solution
                        @solution = solution
                    end

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

                    ##
                    # Provide a user friendly representation
                    def to_s
                        '<Twilio.PreviewIam.Versionless.RoleAssignmentPage>'
                    end
                end
                class RoleAssignmentInstance < InstanceResource
                    ##
                    # Initialize the RoleAssignmentInstance
                    # @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 RoleAssignment
                    #   resource.
                    # @param [String] sid The SID of the Call resource to fetch.
                    # @return [RoleAssignmentInstance] RoleAssignmentInstance
                    def initialize(version, payload , organization_sid: nil, sid: nil)
                        super(version)
                        
                        # Marshaled Properties
                        @properties = { 
                            'sid' => payload['sid'],
                            'role_sid' => payload['role_sid'],
                            'scope' => payload['scope'],
                            'identity' => payload['identity'],
                            'code' => payload['code'],
                            'message' => payload['message'],
                            'more_info' => payload['more_info'],
                            'status' => payload['status'],
                        }

                        # Context
                        @instance_context = nil
                        @params = { 'organization_sid' => organization_sid  || @properties['organization_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 [RoleAssignmentContext] CallContext for this CallInstance
                    def context
                        unless @instance_context
                            @instance_context = RoleAssignmentContext.new(@version , @params['organization_sid'], @params['sid'])
                        end
                        @instance_context
                    end
                    
                    ##
                    # @return [String] Twilio Role Assignment Sid representing this role assignment
                    def sid
                        @properties['sid']
                    end
                    
                    ##
                    # @return [String] Twilio Role Sid representing assigned role
                    def role_sid
                        @properties['role_sid']
                    end
                    
                    ##
                    # @return [String] Twilio Sid representing identity of this assignment
                    def scope
                        @properties['scope']
                    end
                    
                    ##
                    # @return [String] Twilio Sid representing scope of this assignment
                    def identity
                        @properties['identity']
                    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
                    
                    ##
                    # Delete the RoleAssignmentInstance
                    # @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.PreviewIam.Versionless.RoleAssignmentInstance #{values}>"
                    end

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

             end
            end
        end
    end
end


