
    ?h                        d Z ddlmZ ddlmZ ddlmZmZmZm	Z	m
Z
 ddlmZ ddlmZ ddlmZ ddlmZ dd	lmZmZmZmZmZ h d
Zh dZh dZ G d dee      Ze G d d             Z G d d      Z de!de"fdZ#de!de!fdZ$de%de%de%fdZ&y)z
Schema class definition.
    )	dataclass)Enum)UnionOptionalListDictcast)ConnectionError)
Connection)UnexpectedStatusCodeException)Property)_get_dict_from_object_is_sub_schema_capitalize_first_letter_decode_json_response_dict_decode_json_response_list>   class
properties
vectorizerdescriptionmoduleConfigshardingConfigvectorIndexTypereplicationConfigvectorIndexConfigmultiTenancyConfiginvertedIndexConfig>   namedataTyper   r   tokenizationindexInvertedindexFilterableindexSearchable>   int[]date[]text[]uuid[]number[]object[]string[]	boolean[]intblobdatetextuuidnumberobjectstringbooleanphoneNumbergeoCoordinatesc                       e Zd ZdZdZdZy)TenantActivityStatusz
    TenantActivityStatus class used to describe the activity status of a tenant in Weaviate.

    Attributes
    ----------
    HOT: The tenant is fully active and can be used.
    COLD: The tenant is not active, files stored locally.
    HOTCOLDN)__name__
__module____qualname____doc__r9   r:        Y/home/chris/cleankitchens-env/lib/python3.12/site-packages/weaviate/schema/crud_schema.pyr8   r8   E   s     CDr@   r8   c                   x    e Zd ZU dZeed<   ej                  Zeed<   de	eef   fdZ
ede	eef   dd fd       Zy)	Tenantz
    Tenant class used to describe a tenant in Weaviate.

    Attributes
    ----------
    activity_status : TenantActivityStatus, optional
        default: "HOT"
    name: the name of the tenant.
    r   activity_statusreturnc                 4    | j                   | j                  dS )N)activityStatusr   )rD   r   )selfs    rA   _to_weaviate_objectzTenant._to_weaviate_objectb   s    "22II
 	
r@   weaviate_objectc           	      N     | |d   t        |j                  dd                  S )Nr   rG   r9   )r   rD   )r8   get)clsrJ   s     rA   _from_weaviate_objectzTenant._from_weaviate_objecth   s.     (01D1DEUW\1]^
 	
r@   N)r;   r<   r=   r>   str__annotations__r8   r9   rD   r   rI   classmethodrN   r?   r@   rA   rC   rC   S   s]     I,@,D,DO)D
T#s(^ 
 
DcN 
x 
 
r@   rC   c            	          e Zd ZdZdefdZdeeef   ddfdZ	deeef   ddfd	Z
d
eddfdZd!dZd
edefdZd"deeeef      defdZd
ededdfdZd"d
ee   defdZd
edefdZ	 d"d
ededee   defdZdeddfdZdeddfdZdeddfdZdeddfdZd
edee   ddfdZd
edee   ddfdZd
edee   fdZd
edee   ddfd Zy)#Schemaz
    Schema class used to interact and manipulate schemas or classes.

    Attributes
    ----------
    property : weaviate.schema.properties.Property
        A Property object to create new schema property/ies.
    
connectionc                 F    || _         t        | j                         | _        y)z
        Initialize a Schema class instance.

        Parameters
        ----------
        connection : weaviate.connect.Connection
            Connection object to an active and running Weaviate instance.
        N)_connectionr   property)rH   rT   s     rA   __init__zSchema.__init__z   s     & !1!12r@   schemarE   Nc                 j    t        |      }| j                  |d          | j                  |d          y)a  
        Create the schema of the Weaviate instance, with all classes at once.

        Parameters
        ----------
        schema : dict or str
            Schema as a Python dict, or the path to a JSON file, or the URL of a JSON file.

        Examples
        --------
        >>> article_class = {
        ...     "class": "Article",
        ...     "description": "An article written by an Author",
        ...     "properties": [
        ...         {
        ...             "name": "title",
        ...             "dataType": ["text"],
        ...             "description": "The title the article",
        ...         },
        ...         {
        ...             "name": "hasAuthors",
        ...             "dataType": ["Author"],
        ...             "description": "Authors this article has",
        ...         }
        ...     ]
        ... }
        >>> author_class = {
        ...     "class": "Author",
        ...     "description": "An Author class to store the author information",
        ...     "properties": [
        ...         {
        ...             "name": "name",
        ...             "dataType": ["text"],
        ...             "description": "The name of the author",
        ...         },
        ...         {
        ...             "name": "wroteArticles",
        ...             "dataType": ["Article"],
        ...             "description": "The articles of the author",
        ...         }
        ...     ]
        ... }
        >>> client.schema.create({"classes": [article_class, author_class]})

        If you have your schema saved in the './schema/my_schema.json' you can create it
        directly from the file.

        >>> client.schema.create('./schema/my_schema.json')

        Raises
        ------
        TypeError
            If the 'schema' is neither a string nor a dict.
        ValueError
            If 'schema' can not be converted into a Weaviate schema.
        requests.ConnectionError
            If the network connection to Weaviate fails.
        weaviate.UnexpectedStatusCodeException
            If Weaviate reports a non-OK status.
        weaviate.SchemaValidationException
            If the 'schema' could not be validated against the standard format.
        classesN)r   _create_classes_with_primitives'_create_complex_properties_from_classes)rH   rY   loaded_schemas      rA   createzSchema.create   s5    @ .f5,,]9-EF44]95MNr@   schema_classc                 ^    t        |      }| j                  |       | j                  |       y)a  
        Create a single class as part of the schema in Weaviate.

        Parameters
        ----------
        schema_class : dict or str
            Class as a Python dict, or the path to a JSON file, or the URL of a JSON file.

        Examples
        --------
        >>> author_class_schema = {
        ...     "class": "Author",
        ...     "description": "An Author class to store the author information",
        ...     "properties": [
        ...         {
        ...             "name": "name",
        ...             "dataType": ["text"],
        ...             "description": "The name of the author",
        ...         },
        ...         {
        ...             "name": "wroteArticles",
        ...             "dataType": ["Article"],
        ...             "description": "The articles of the author",
        ...         }
        ...     ]
        ... }
        >>> client.schema.create_class(author_class_schema)

        If you have your class schema saved in the './schema/my_schema.json' you can create it
        directly from the file.

        >>> client.schema.create_class('./schema/my_schema.json')

        Raises
        ------
        TypeError
            If the 'schema_class' is neither a string nor a dict.
        ValueError
            If 'schema_class' can not be converted into a Weaviate schema.
        requests.ConnectionError
            If the network connection to Weaviate fails.
        weaviate.UnexpectedStatusCodeException
            If Weaviate reports a non-OK status.
        weaviate.SchemaValidationException
            If the 'schema_class' could not be validated against the standard format.
        N)r   _create_class_with_primitives%_create_complex_properties_from_class)rH   r`   loaded_schema_classs      rA   create_classzSchema.create_class   s.    ` 4LA**+>?223FGr@   
class_namec                    t        |t              st        dt        |       d      dt	        |       }	 | j
                  j                  |      }|j                  dk7  rt        d|      y# t        $ r}t        d      |d}~ww xY w)	aI  
        Delete a schema class from Weaviate. This deletes all associated data.

        Parameters
        ----------
        class_name : str
            The class that should be deleted from Weaviate.

        Examples
        --------
        >>> client.schema.delete_class('Author')

        Raises
        ------
        TypeError
            If 'class_name' argument not of type str.
        requests.ConnectionError
            If the network connection to Weaviate fails.
        weaviate.UnexpectedStatusCodeException
            If Weaviate reports a non-OK status.
        zClass name was z instead of str/schema/pathzDeletion of class.N   zDelete class from schema)

isinstancerO   	TypeErrortyper   rV   deleteRequestsConnectionErrorstatus_coder   rH   rf   rj   responseconn_errs        rA   delete_classzSchema.delete_class   s    . *c*od:.>-?OPP2:>?@	N''..D.9H 3&/0JHUU ' ' 	N)*>?XM	Ns   A0 0	B
9BB
c                 ~    | j                         }|j                  dg       }|D ]  }| j                  |d           y)z
        Remove the entire schema from the Weaviate instance and all data associated with it.

        Examples
        --------
        >>> client.schema.delete_all()
        r[   r   N)rL   ru   )rH   rY   r[   _classs       rA   
delete_allzSchema.delete_all!  s@     **Y+ 	/FfWo.	/r@   c                 :   t        |t              st        dt        |       d      dt	        |       }	 | j
                  j                  |      }|j                  dk(  ry|j                  d	k(  ry
t        d|      # t        $ r}t        d      |d}~ww xY w)a  
        Check if class exists in Weaviate.

        Parameters
        ----------
        class_name : str
            The class whose existence is being checked.

        Examples
        --------
        >>> client.schema.exists(class_name="Exists")
        True

        >>> client.schema.exists(class_name="DoesNotExists")
        False

        Returns
        -------
        bool
            True if the class exists,
            False otherwise.
        9'class_name' argument must be of type `str`! Given type: .rh   ri   z+Checking class existence could not be done.Nrk   Ti  FzCheck if class exists)
rl   rO   rm   rn   r   rV   rL   rp   rq   r   rr   s        rA   existszSchema.exists/  s    0 *c*KDQ[L\K]]^_  2:>?@	''+++6H
 3&!!S(+,CXNN ' 	)=	s   B   	B	BBc                 z    | j                         }|t        |      }t        ||      S t        |d         dk(  ryy)a  
        Check if Weaviate already contains a schema.

        Parameters
        ----------
        schema : dict or str, optional
            Schema as a Python dict, or the path to a JSON file or the URL of a JSON file.
            If a schema is given it is checked if this specific schema is already loaded.
            It will test only this schema. If the given schema is a subset of the loaded
            schema it will still return true, by default None.

        Examples
        --------
        >>> schema = client.schema.get()
        >>> client.schema.contains(schema)
        True
        >>> schema = client.schema.get()
        >>> schema['classes'].append(
            {
                "class": "Animal",
                "description": "An Animal",
                "properties": [
                    {
                        "name": "type",
                        "dataType": ["text"],
                        "description": "The animal type",
                    }
                ]
            }
        )
        >>> client.schema.contains(schema)
        False

        Returns
        -------
        bool
            True if a schema is present,
            False otherwise.
        r[   r   FT)rL   r   r   len)rH   rY   r^   
sub_schemas       rA   containszSchema.contains[  sE    R 
.v6J!*m<<}Y'(A-r@   configc                 
   t        |      }| j                  |      }t        ||      }d|z   }	 | j                  j	                  ||      }|j                  dk7  rt        d|      y# t
        $ r}t        d      |d}~ww xY w)a  
        Update a schema configuration for a specific class.

        Parameters
        ----------
        class_name : str
            The class for which to update the schema configuration.
        config : dict
            The configurations to update (MUST follow schema format).

        Example
        -------
        In the example below we have a Weaviate instance with a class 'Test'.

        >>> client.schema.get('Test')
        {
            'class': 'Test',
            ...
            'vectorIndexConfig': {
                'ef': -1,
                ...
            },
            ...
        }
        >>> client.schema.update_config(
        ...     class_name='Test',
        ...     config={
        ...         'vectorIndexConfig': {
        ...             'ef': 100,
        ...         }
        ...     }
        ... )
        >>> client.schema.get('Test')
        {
            'class': 'Test',
            ...
            'vectorIndexConfig': {
                'ef': 100,
                ...
            },
            ...
        }

        NOTE: When updating schema configuration, the 'config' MUST be sub-set of the schema,
        starting at the top level. In the example above we update 'ef' value, and for this we
        included the 'vectorIndexConfig' top level too.

        Raises
        ------
        requests.ConnectionError
            If the network connection to Weaviate fails.
        weaviate.UnexpectedStatusCodeException
            If Weaviate reports a non-OK status.
        rh   rj   rJ   z0Class schema configuration could not be updated.Nrk   z!Update class schema configuration)r   rL   _update_nested_dictrV   putrp   rq   r   )rH   rf   r   class_schemanew_class_schemarj   rs   rt   s           rA   update_configzSchema.update_config  s    p .j9
xx
+.|VDJ&	''++GW+XH
 3&/0SU]^^ '	 ' 	)B	s   A( (	B1A==Bc                    d}|5t        |t              st        dt        |             dt	        |       }	 | j
                  j                  |      }t        |d      }|J |S # t        $ r}t        d      |d}~ww xY w)ao
  
        Get the schema from Weaviate.

        Parameters
        ----------
        class_name : str, optional
            The class for which to return the schema. If NOT provided the whole schema is returned,
            otherwise only the schema of this class is returned. By default None.

        Returns
        -------
        dict
            A dict containing the schema. The schema may be empty.
            To see if a schema has already been loaded, use the `contains` method.

        Examples
        --------
        No schema present in client

        >>> client.schema.get()
        {'classes': []}

        Schema present in client

        >>> client.schema.get()
        {
            "classes": [
                {
                "class": "Animal",
                "description": "An Animal",
                "invertedIndexConfig": {
                    "cleanupIntervalSeconds": 60
                },
                "properties": [
                    {
                    "dataType": ["text"],
                    "description": "The animal type",
                    "name": "type"
                    }
                ],
                "vectorIndexConfig": {
                    "cleanupIntervalSeconds": 300,
                    "maxConnections": 64,
                    "efConstruction": 128,
                    "vectorCacheMaxObjects": 500000
                },
                "vectorIndexType": "hnsw",
                "vectorizer": "text2vec-contextionary",
                "replicationConfig": {
                    "factor": 1
                }
                }
            ]
        }

        >>> client.schema.get('Animal')
        {
            "class": "Animal",
            "description": "An Animal",
            "invertedIndexConfig": {
                "cleanupIntervalSeconds": 60
            },
            "properties": [
                {
                "dataType": ["text"],
                "description": "The animal type",
                "name": "type"
                }
            ],
            "vectorIndexConfig": {
                "cleanupIntervalSeconds": 300,
                "maxConnections": 64,
                "efConstruction": 128,
                "vectorCacheMaxObjects": 500000
            },
            "vectorIndexType": "hnsw",
            "vectorizer": "text2vec-contextionary",
            "replicationConfig": {
                "factor": 1
            }
        }

        Raises
        ------
        requests.ConnectionError
            If the network connection to Weaviate fails.
        weaviate.UnexpectedStatusCodeException
            If Weaviate reports a non-OK status.
        /schemaNrz   rh   ri   zSchema could not be retrieved.z
Get schema)	rl   rO   rm   rn   r   rV   rL   rp   r   rH   rf   rj   rs   rt   ress         rA   rL   z
Schema.get  s    v !j#.##'
#3"46  6zBCDD	Z''+++6H )<@
 ' 	Z)*JKQYY	Zs   A) )	B2A>>Bc                    t        |t              st        dt        |       d      dt	        |       d}	 | j
                  j                  |      }t        |d      }|J |S # t        $ r}t        d      |d}~ww xY w)	a  
        Get the status of all shards in an index.

        Parameters
        ----------
        class_name : str
            The class for which to return the status of all shards in an index.

        Returns
        -------
        list
            The list of shards configuration.

        Examples
        --------
        Schema contains a single class: Article

        >>> client.schema.get_class_shards('Article')
        [{'name': '2rPgsA2yngW3', 'status': 'READY'}]

        Raises
        ------
        requests.ConnectionError
            If the network connection to Weaviate fails.
        weaviate.UnexpectedStatusCodeException
            If Weaviate reports a non-OK status.
        rz   r{   rh   z/shardsri   zDClass shards' status could not be retrieved due to connection error.NzGet shards' status)	rl   rO   rm   rn   r   rV   rL   rp   r   r   s         rA   get_class_shardszSchema.get_class_shardsA  s    : *c*NtT^O_N``ab  2:>?wG	''+++6H )3GH
 ' 	)V	s   A' '	B0A<<Bstatus
shard_namec           	      z   t        |t              st        dt        |       d      t        |t              s|t        dt        |       d      t        |t              st        dt        |       d      |%| j	                  |      }|D cg c]  }|d   	 }}n|g}d|i}g }|D ]P  }	d	t        |       d
|	 }
	 | j                  j                  |
|      }|j                  t        |d|	 d             R ||S t        t        |d         S c c}w # t        $ r}t        d|	 d      |d}~ww xY w)au  
        Get the status of all shards in an index.

        Parameters
        ----------
        class_name : str
            The class for which to update the status of all shards in an index.
        status : str
            The new status of the shard. The available options are: 'READY' and 'READONLY'.
        shard_name : str or None, optional
            The shard name for which to update the status of the class of the shard. If None then
            all the shards are going to be updated to the 'status'. By default None.

        Returns
        -------
        list
            The updated statuses.

        Examples
        --------
        Schema contains a single class: Article

        >>> client.schema.get_class_shards('Article')
        [{'name': 'node1', 'status': 'READY'}, {'name': 'node2', 'status': 'READY'}]

        For a specific shard:

        >>> client.schema.update_class_shard('Article', 'READONLY', 'node2')
        {'status': 'READONLY'}
        >>> client.schema.get_class_shards('Article')
        [{'name': 'node1', 'status': 'READY'}, {'name': 'node2', 'status': 'READONLY'}]

        For all shards of the class:

        >>> client.schema.update_class_shard('Article', 'READONLY')
        [{'status': 'READONLY'},{'status': 'READONLY'}]
        >>> client.schema.get_class_shards('Article')
        [{'name': 'node1', 'status': 'READONLY'}, {'name': 'node2', 'status': 'READONLY'}]


        Raises
        ------
        requests.ConnectionError
            If the network connection to Weaviate fails.
        weaviate.UnexpectedStatusCodeException
            If Weaviate reports a non-OK status.
        rz   r{   Nz9'shard_name' argument must be of type `str`! Given type: z5'status' argument must be of type `str`! Given type: )rf   r   r   rh   z/shards/r   z5Class shards' status could not be updated for shard 'z' due to connection error.zUpdate shard 'z' statusr   )rl   rO   rm   rn   r   r   rV   r   rp   appendr   r	   list)rH   rf   r   r   shards_configshard_configshard_namesdata	to_return_shard_namerj   rs   rt   s                rA   update_class_shardzSchema.update_class_shardo  s   l *c*NtT^O_N``ab  *c*z/ENtT^O_N``ab  &#&J4PV<.XYZ   11% 2 M ERRL</RKR%,K&!	& 	K6zBC8K=YD	 ++//$( 0  *8~k]RZ5[\	" D)A,''7 S +  -KK= Y( (    s   DD	D:%D55D:c                    d|vry|d   D ]  }t        |d         r|d   D cg c]  }t        |       c}|d   d}t        ddhz
  D ]  }||v s||   ||<    dt        |d         z   dz   }	 | j                  j	                  ||	      }|j                  dk7  st        d|       yc c}w # t
        $ r}t        d
      |d}~ww xY w)a  
        Add cross-references to an already existing class.

        Parameters
        ----------
        schema_class : dict
            Description of the class that should be added.

        Raises
        ------
        requests.ConnectionError
            If the network connection to Weaviate fails.
        weaviate.UnexpectedStatusCodeException
            If Weaviate reports a non-OK status.
        r   Nr   r   )r   r   rh   r   z/propertiesr   z,Property may not have been created properly.rk   zAdd properties to classes)_property_is_primitiver   PROPERTY_KEYSrV   postrp   rq   r   )	rH   r`   	property_dtypeschema_propertyproperty_fieldrj   rs   rt   s	            rA   rc   z,Schema._create_complex_properties_from_class  s   " |+%l3 	[I%i
&;< KTT^J_`5e<`!&)O
 #06:2F"F P!Y.6?6OON3P  8g9N OOR__D ++00dO0\
 ##s*34OQYZZ-	[ a +  -B  s   B,1B11	C:CCschema_classes_listc                 4    |D ]  }| j                  |        y)z
        Add cross-references to already existing classes.

        Parameters
        ----------
        schema_classes_list : list
            A list of classes as they are found in a schema JSON description.
        N)rc   )rH   r   r`   s      rA   r]   z.Schema._create_complex_properties_from_classes  s#     0 	EL66|D	Er@   weaviate_classc                 6   t        |d         g d}t        ddhz
  D ]  }||v s||   ||<    d|v rt        |d         |d<   	 | j                  j	                  d|      }|j                  dk7  rt        d	|      y# t
        $ r}t        d      |d}~ww xY w)
a  
        Create class with only primitives.

        Parameters
        ----------
        weaviate_class : dict
            A single Weaviate formatted class

        Raises
        ------
        requests.ConnectionError
            If the network connection to Weaviate fails.
        weaviate.UnexpectedStatusCodeException
            If Weaviate reports a non-OK status.
        r   )r   r   r   r   r   z)Class may not have been created properly.Nrk   zCreate class)r   
CLASS_KEYS_get_primitive_propertiesrV   r   rp   rq   r   )rH   r   r`   class_fieldrs   rt   s         rA   rb   z$Schema._create_class_with_primitives  s    & .nW.EF

 &,(?? 	HKn,,:;,G[)	H >))B>R^C_)`L&	e'',,)\,ZH 3&/II ' ' 	e)*UV\dd	es   A> >	BBBc                 4    |D ]  }| j                  |        y)aV  
        Create all the classes in the list and primitive properties.
        This function does not create references,
        to avoid references to classes that do not yet exist.

        Parameters
        ----------
        schema_classes_list : list
            A list of classes as they are found in a schema JSON description.
        N)rb   )rH   r   r   s      rA   r\   z&Schema._create_classes_with_primitives2  s!     2 	?N..~>	?r@   tenantsc                    |D cg c]  }|j                          }}dt        |       d}	 | j                  j                  ||      }|j
                  dk7  rt        d|      yc c}w # t        $ r}t	        d      |d}~ww xY w)a  
        Add class's tenants in Weaviate.

        Parameters
        ----------
        class_name : str
            The class for which we add tenants.
        tenants : List[Tenant]
            List of Tenants.

        Examples
        --------
        >>> tenants = [ Tenant(name="Tenant1"), Tenant(name="Tenant2") ]
        >>> client.schema.add_class_tenants("class_name", tenants)

        Raises
        ------
        TypeError
            If 'tenants' has not the correct type.
        requests.ConnectionError
            If the network connection to Weaviate fails.
        weaviate.UnexpectedStatusCodeException
            If Weaviate reports a non-OK status.
        rh   /tenantsr   z1Classes tenants may not have been added properly.Nrk   zAdd classes tenants)rI   r   rV   r   rp   rq   r   )rH   rf   r   tenantloaded_tenantsrj   rs   rt   s           rA   add_class_tenantszSchema.add_class_tenantsA  s    4 FMM6&446MM2:>?xH	'',,$,WH
 3&/0ExPP ' N
 ' 	)C	s   A'A, ,	B5BBc                     dt        |       d}	 | j                  j                  ||      }|j                  dk7  rt        d|      y# t        $ r}t        d      |d}~ww xY w)a  
        Remove class's tenants in Weaviate.

        Parameters
        ----------
        class_name : str
            The class for which we remove tenants.
        tenants : List[str]
            List of tenant names to remove from the given class.

        Examples
        --------
        >>> client.schema.remove_class_tenants("class_name", ["Tenant1", "Tenant2"])

        Raises
        ------
        TypeError
            If 'tenants' has not the correct type.
        requests.ConnectionError
            If the network connection to Weaviate fails.
        weaviate.UnexpectedStatusCodeException
            If Weaviate reports a non-OK status.
        rh   r   r   z*Classes tenants may not have been deleted.Nrk   zDelete classes tenants)r   rV   ro   rp   rq   r   )rH   rf   r   rj   rs   rt   s         rA   remove_class_tenantszSchema.remove_class_tenantsg  s    0 2:>?xH	''..D'.RH
 3&/0H(SS '	 ' 	)<	s   A
 
	A$AA$c                    dt        |       d}	 | j                  j                  |      }t	        |d      }|J |D cg c]  }t
        j                  |       c}S # t        $ r}t        d      |d}~ww xY wc c}w )a  Get class's tenants in Weaviate.

        Parameters
        ----------
        class_name : str
            The class for which we get tenants.

        Examples
        --------
        >>> client.schema.get_class_tenants("class_name")

        Raises
        ------
        requests.ConnectionError
            If the network connection to Weaviate fails.
        weaviate.UnexpectedStatusCodeException
            If Weaviate reports a non-OK status.
        rh   r   ri   zCould not get class tenants.NzGet class tenants)r   rV   rL   rp   r   rC   rN   )rH   rf   rj   rs   rt   tenant_respr   s          rA   get_class_tenantszSchema.get_class_tenants  s    & 2:>?xH	X''+++6H 1;NO&&&CNO,,V4OO ' 	X)*HIxW	X
 Ps   A  A= 	A:)A55A:c                    dt        |       d}|D cg c]  }|j                          }}	 | j                  j                  ||      }|j
                  dk7  rt        d|      yc c}w # t        $ r}t	        d      |d}~ww xY w)a  Update class tenants.

        Use this when you want to move tenants from one activity state to another.

        Parameters
        ----------
        class_name : str
            The class for which we update tenants.
        tenants : List[Tenant]
            List of Tenants.

        Examples
        --------
        >>> client.schema.add_class_tenants(
                "class_name",
                [
                    Tenant(activity_status=TenantActivityStatus.HOT, name="Tenant1")),
                    Tenant(activity_status=TenantActivityStatus.COLD, name="Tenant2"))
                    Tenant(name="Tenant3")
                ]
            )
        >>> client.schema.update_class_tenants(
                "class_name",
                [
                    Tenant(activity_status=TenantActivityStatus.COLD, name="Tenant1")),
                    Tenant(activity_status=TenantActivityStatus.HOT, name="Tenant2"))
                ]
            )
        >>> client.schema.get_class_tenants("class_name")
        [
            Tenant(activity_status=TenantActivityStatus.COLD, name="Tenant1")),
            Tenant(activity_status=TenantActivityStatus.HOT, name="Tenant2")),
            Tenant(activity_status=TenantActivityStatus.HOT, name="Tenant3"))
        ]


        Raises
        ------
        requests.ConnectionError
            If the network connection to Weaviate fails.
        weaviate.UnexpectedStatusCodeException
            If Weaviate reports a non-OK status.
        rh   r   r   zCould not update class tenants.Nrk   zUpdate classes tenants)r   rI   rV   r   rp   rq   r   )rH   rf   r   rj   r   r   rs   rt   s           rA   update_class_tenantszSchema.update_class_tenants  s    X 2:>?xHELM6&446MM	[''++~+VH 3&/0H(SS ' N ' 	[)*KLRZZ	[s   A'A, ,	B5BB)rE   N)N) r;   r<   r=   r>   r   rX   r   dictrO   r_   re   ru   rx   boolr|   r   r   r   rL   r   r   r   rc   r]   rb   r\   r   rC   r   r   r   r   r?   r@   rA   rS   rS   p   s   3: 3BOU49- BO$ BOH2HtSy)9 2Hd 2Hh Vs  Vt  VD/*O *O *OX1xdCi(89 1T 1fD_ D_T D_d D_Lkhsm kt kZ,3 ,4 ,d %)	b(b( b( SM	b(
 
b(H*[$ *[4 *[XE4 ETX E$JD $JT $JL?4 ?D ?$QC $Q$v, $Q4 $QL Ts  TT#Y  T4  TDPC PDL P:3Ts 3TT&\ 3Td 3Tr@   rS   data_type_listrE   c                 B    t        t        |       t        z
        dk(  ryy)a  
    Check if the property is primitive.

    Parameters
    ----------
    data_type_list : list
        Data types to be checked if are primitive.

    Returns
    -------
    bool
        True if it only consists of primitive data types,
        False otherwise.
    r   TF)r~   set_PRIMITIVE_WEAVIATE_TYPES_SET)r   s    rA   r   r     s"      3~!>>?1Dr@   properties_listc                 X    g }| D ]"  }t        |d         s|j                  |       $ |S )a  
    Filter the list of properties for only primitive properties.

    Parameters
    ----------
    properties_list : list
        A list of properties to extract the primitive properties.

    Returns
    -------
    list
        A list of properties containing only primitives.
    r   )r   r   )r   primitive_propertiesr   s      rA   r   r     s?     $ /	%i
&;<##I.	/
  r@   dict_1dict_2c                     |j                         D ]B  \  }}|| vr|| |<   t        |t              rt        | |   |       0| j	                  ||i       D | S )a  
    Update `dict_1` with elements from `dict_2` in a nested manner.
    If a value of a key is a dict, it is going to be updated and not replaced by the whole dict.

    Parameters
    ----------
    dict_1 : dict
        The dictionary to be updated.
    dict_2 : dict
        The dictionary that contains values to be updated.

    Returns
    -------
    dict
        The updated `dict_1`.
    )itemsrl   r   r   update)r   r   keyvalues       rA   r   r   	  s`    " lln (
UfF3KeT"sU3MM3,'( Mr@   N)'r>   dataclassesr   enumr   typingr   r   r   r   r	   requests.exceptionsr
   rp   weaviate.connectr   weaviate.exceptionsr   weaviate.schema.propertiesr   weaviate.utilr   r   r   r   r   r   r   r   rO   r8   rC   rS   r   r   r   r   r   r   r?   r@   rA   <module>r      s    "  4 4 J ' = / 
	! .3  
 
 
8iT iTX4 D * t    0 d t r@   