##
#    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 UserList < ListResource
                
                    class ScimUser
                            # @param [id]: [String] Unique Twilio user sid
                            # @param [external_id]: [String] External unique resource id defined by provisioning client
                            # @param [user_name]: [String] Unique username, MUST be same as primary email address
                            # @param [display_name]: [String] User friendly display name
                            # @param [name]: [UserList.ScimName] 
                            # @param [emails]: [Array<UserList.ScimEmailAddress>] Email address list of the user. Primary email must be defined if there are more than 1 email. Primary email must match the username.
                            # @param [active]: [Boolean] Indicates whether the user is active
                            # @param [locale]: [String] User's locale
                            # @param [timezone]: [String] User's time zone
                            # @param [schemas]: [Array<String>] An array of URIs that indicate the schemas supported for this user resource
                            # @param [meta]: [UserList.ScimMeta] 
                            # @param [detail]: [String] A human-readable description of the error
                            # @param [scim_type]: [String] A scimType error code as defined in RFC7644
                            # @param [status]: [String] Http status code
                            # @param [code]: [String] Twilio-specific error code
                            # @param [more_info]: [String] Link to Error Code References
                        attr_accessor :id, :external_id, :user_name, :display_name, :name, :emails, :active, :locale, :timezone, :schemas, :meta, :detail, :scim_type, :status, :code, :more_info
                        def initialize(payload)
                                @id = payload["id"]
                                @external_id = payload["external_id"]
                                @user_name = payload["user_name"]
                                @display_name = payload["display_name"]
                                @name = payload["name"]
                                @emails = payload["emails"]
                                @active = payload["active"]
                                @locale = payload["locale"]
                                @timezone = payload["timezone"]
                                @schemas = payload["schemas"]
                                @meta = payload["meta"]
                                @detail = payload["detail"]
                                @scim_type = payload["scim_type"]
                                @status = payload["status"]
                                @code = payload["code"]
                                @more_info = payload["more_info"]
                        end
                        def to_json(options = {})
                        {
                                "id": @id,
                                "externalId": @external_id,
                                "userName": @user_name,
                                "displayName": @display_name,
                                "name": @name,
                                "emails": @emails,
                                "active": @active,
                                "locale": @locale,
                                "timezone": @timezone,
                                "schemas": @schemas,
                                "meta": @meta,
                                "detail": @detail,
                                "scimType": @scim_type,
                                "status": @status,
                                "code": @code,
                                "moreInfo": @more_info,
                        }.to_json(options)
                        end
                    end


                    ##
                    # Initialize the UserList
                    # @param [Version] version Version that contains the resource
                    # @return [UserList] UserList
                    def initialize(version, organization_sid: nil)
                        super(version)
                        # Path Solution
                        @solution = { organization_sid: organization_sid }
                        @uri = "/#{@solution[:organization_sid]}/scim/Users"
                        
                    end
                    ##
                    # Create the UserInstance
                    # @param [ScimUser] scim_user 
                    # @return [UserInstance] Created UserInstance
                    def create(scim_user: nil
                    )

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

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

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

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

                    ##
                    # When passed a block, yields UserInstance 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 UserInstance records from the API.
                    # Request is executed immediately.
                    # @param [String] filter 
                    # @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 UserInstance
                    def page(filter: :unset, page_token: :unset, page_number: :unset, page_size: :unset)
                        params = Twilio::Values.of({
                            'filter' => filter,
                            'PageToken' => page_token,
                            'Page' => page_number,
                            'PageSize' => page_size,
                        })
                        headers = Twilio::Values.of({})
                        
                        headers['Accept'] = 'application/scim+json'

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

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

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


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


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

                        # Path Solution
                        @solution = { organization_sid: organization_sid, id: id,  }
                        @uri = "/#{@solution[:organization_sid]}/scim/Users/#{@solution[:id]}"

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

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

                        headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', })
                        
                        
                        
                        headers['Accept'] = 'application/scim+json'
                        
                        payload = @version.fetch('GET', @uri, headers: headers)
                        UserInstance.new(
                            @version,
                            payload,
                            organization_sid: @solution[:organization_sid],
                            id: @solution[:id],
                        )
                    end

                    ##
                    # Update the UserInstance
                    # @param [String] if_match 
                    # @param [ScimUser] scim_user 
                    # @return [UserInstance] Updated UserInstance
                    def update(
                        if_match: :unset,scim_user: nil
                    )

                        headers = Twilio::Values.of({'Content-Type' => 'application/x-www-form-urlencoded', 'If-Match' => if_match, })
                        
                        headers['Content-Type'] = 'application/scim+json'
                        
                        headers['Accept'] = 'application/scim+json'
                        
                        payload = @version.update('PUT', @uri, headers: headers, data: scim_user.to_json)
                        UserInstance.new(
                            @version,
                            payload,
                            organization_sid: @solution[:organization_sid],
                            id: @solution[:id],
                        )
                    end


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

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

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

                        # Path Solution
                        @solution = solution
                    end

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

                    ##
                    # Provide a user friendly representation
                    def to_s
                        '<Twilio.PreviewIam.Versionless.UserPage>'
                    end
                end
                class UserInstance < InstanceResource
                    ##
                    # Initialize the UserInstance
                    # @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 User
                    #   resource.
                    # @param [String] sid The SID of the Call resource to fetch.
                    # @return [UserInstance] UserInstance
                    def initialize(version, payload , organization_sid: nil, id: nil)
                        super(version)
                        
                        # Marshaled Properties
                        @properties = { 
                            'id' => payload['id'],
                            'external_id' => payload['external_id'],
                            'user_name' => payload['user_name'],
                            'display_name' => payload['display_name'],
                            'name' => payload['name'],
                            'emails' => payload['emails'],
                            'active' => payload['active'],
                            'locale' => payload['locale'],
                            'timezone' => payload['timezone'],
                            'schemas' => payload['schemas'],
                            'meta' => payload['meta'],
                            'detail' => payload['detail'],
                            'scim_type' => payload['scim_type'],
                            'status' => payload['status'],
                            'code' => payload['code'],
                            'more_info' => payload['more_info'],
                        }

                        # Context
                        @instance_context = nil
                        @params = { 'organization_sid' => organization_sid  || @properties['organization_sid']  ,'id' => id  || @properties['id']  , }
                    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 [UserContext] CallContext for this CallInstance
                    def context
                        unless @instance_context
                            @instance_context = UserContext.new(@version , @params['organization_sid'], @params['id'])
                        end
                        @instance_context
                    end
                    
                    ##
                    # @return [String] Unique Twilio user sid
                    def id
                        @properties['id']
                    end
                    
                    ##
                    # @return [String] External unique resource id defined by provisioning client
                    def external_id
                        @properties['external_id']
                    end
                    
                    ##
                    # @return [String] Unique username, MUST be same as primary email address
                    def user_name
                        @properties['user_name']
                    end
                    
                    ##
                    # @return [String] User friendly display name
                    def display_name
                        @properties['display_name']
                    end
                    
                    ##
                    # @return [UserList.ScimName] 
                    def name
                        @properties['name']
                    end
                    
                    ##
                    # @return [Array<UserList.ScimEmailAddress>] Email address list of the user. Primary email must be defined if there are more than 1 email. Primary email must match the username.
                    def emails
                        @properties['emails']
                    end
                    
                    ##
                    # @return [Boolean] Indicates whether the user is active
                    def active
                        @properties['active']
                    end
                    
                    ##
                    # @return [String] User's locale
                    def locale
                        @properties['locale']
                    end
                    
                    ##
                    # @return [String] User's time zone
                    def timezone
                        @properties['timezone']
                    end
                    
                    ##
                    # @return [Array<String>] An array of URIs that indicate the schemas supported for this user resource
                    def schemas
                        @properties['schemas']
                    end
                    
                    ##
                    # @return [UserList.ScimMeta] 
                    def meta
                        @properties['meta']
                    end
                    
                    ##
                    # @return [String] A human-readable description of the error
                    def detail
                        @properties['detail']
                    end
                    
                    ##
                    # @return [String] A scimType error code as defined in RFC7644
                    def scim_type
                        @properties['scim_type']
                    end
                    
                    ##
                    # @return [String] Http status code
                    def status
                        @properties['status']
                    end
                    
                    ##
                    # @return [String] Twilio-specific error code
                    def code
                        @properties['code']
                    end
                    
                    ##
                    # @return [String] Link to Error Code References
                    def more_info
                        @properties['more_info']
                    end
                    
                    ##
                    # Delete the UserInstance
                    # @return [Boolean] True if delete succeeds, false otherwise
                    def delete

                        context.delete
                    end

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

                        context.fetch
                    end

                    ##
                    # Update the UserInstance
                    # @param [String] if_match 
                    # @param [ScimUser] scim_user 
                    # @return [UserInstance] Updated UserInstance
                    def update(
                        if_match: :unset,scim_user: nil
                    )

                        context.update(
                            if_match: if_match, 
                        )
                    end

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

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

             end
            end
        end
    end
end


