
    ѮhX                    4   d Z ddlmZ ddlZddlmZmZmZmZm	Z	m
Z
mZ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 erDddlmZ dd	lmZ dd
l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( ddl)m*Z* ddl+m,Z, ddl-m.Z. dZ/ G d dee         Z0ddZ1ddZ2y)zHClasses for representing collections for the Google Cloud Firestore API.    )annotationsN)TYPE_CHECKINGAnyAsyncGeneratorAsyncIterator	Coroutine	GeneratorGenericIterableSequenceTupleUnionOptional)retry)_helpers)	QueryType)BaseAggregationQuery)DocumentSnapshot)BaseVectorQueryDistanceMeasure)DocumentReference)	FieldPath)ExplainOptions)QueryResultsList)StreamGenerator)Transaction)Vector)VectorQuery>ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789c                  ,   e Zd ZdZd&dZd Zed        Zed        Zd'dZ	d(dZ
d)dZd*d+d
Zd,dZ	 	 	 d-	 	 	 	 	 	 	 	 	 d.dZ	 	 	 d-	 	 	 	 	 	 	 	 	 d/dZ	 	 	 d-	 	 	 	 	 	 	 d0dZ	 	 	 d-	 	 	 	 	 	 	 d1dZd'dZd2dZ	 	 	 d-d	d	 	 	 	 	 d3dZd4dZd5dZd6dZd7dZ	 	 	 	 d8dZ	 	 	 	 d8dZ	 	 	 	 d8dZ	 	 	 	 d8dZ	 	 d9	 	 	 	 	 d:dZ	 	 	 d-d	d	 	 	 	 	 	 	 	 	 d;dZ	 	 	 d-d	d	 	 	 	 	 	 	 	 	 d<dZd  Z d*d!Z!d*d=d"Z"d*d=d#Z#d	d	d$	 	 	 	 	 	 	 	 	 	 	 	 	 d>d%Z$y	)?BaseCollectionReferencea  A reference to a collection in a Firestore database.

    The collection may already exist or this class can facilitate creation
    of documents within the collection.

    Args:
        path (Tuple[str, ...]): The components in the collection path.
            This is a series of strings representing each collection and
            sub-collection ID, as well as the document IDs for any documents
            that contain a sub-collection.
        kwargs (dict): The keyword arguments for the constructor. The only
            supported keyword is ``client`` and it must be a
            :class:`~google.cloud.firestore_v1.client.Client` if provided. It
            represents the client that created this collection reference.

    Raises:
        ValueError: if

            * the ``path`` is empty
            * there are an even number of elements
            * a collection ID in ``path`` is not a string
            * a document ID in ``path`` is not a string
        TypeError: If a keyword other than ``client`` is used.
    c                    t        j                  |d       || _        |j                  dd       | _        |rt        d|d      y )NT)is_collectionclientzReceived unexpected argumentszOnly `client` is supported)r   verify_path_pathpop_client	TypeError)selfpathkwargss      {/home/www/academy-backend.kofcorporation.com/venv/lib/python3.12/site-packages/google/cloud/firestore_v1/base_collection.py__init__z BaseCollectionReference.__init__U   sH    T6
zz(D1/9U      c                    t        || j                        st        S | j                  |j                  k(  xr | j                  |j                  k(  S N)
isinstance	__class__NotImplementedr&   r(   )r*   others     r-   __eq__zBaseCollectionReference.__eq__^   s;    %0!!zzU[[(JT\\U]]-JJr/   c                     | j                   d   S )zfThe collection identifier.

        Returns:
            str: The last component of the path.
        )r&   r*   s    r-   idzBaseCollectionReference.idc   s     zz"~r/   c                    t        | j                        dk(  ry| j                  dd } | j                  j                  | S )a  Document that owns the current collection.

        Returns:
            Optional[:class:`~google.cloud.firestore_v1.document.DocumentReference`]:
            The parent document, if the current collection is not a
            top-level collection.
           Nr8   )lenr&   r(   document)r*   parent_paths     r-   parentzBaseCollectionReference.parentl   s=     tzz?a**Sb/K$t||$$k22r/   c                    t         r1   NotImplementedErrorr9   s    r-   _queryzBaseCollectionReference._query{       !!r/   c                    t         r1   rB   r9   s    r-   _aggregation_queryz*BaseCollectionReference._aggregation_query~   rE   r/   c                    t         r1   rB   r9   s    r-   _vector_queryz%BaseCollectionReference._vector_query   rE   r/   Nc                    |
t               }| j                  d   r| j                  |fz   n|f} | j                  j                  | S )a  Create a sub-document underneath the current collection.

        Args:
            document_id (Optional[str]): The document identifier
                within the current collection. If not provided, will default
                to a random 20 character string composed of digits,
                uppercase and lowercase and letters.

        Returns:
            :class:`~google.cloud.firestore_v1.document.DocumentReference`:
            The child document.
        r   )_auto_idr&   r(   r>   )r*   document_id
child_paths      r-   r>   z BaseCollectionReference.document   sH     "*K
 59JJqMTZZ;.0~
$t||$$j11r/   c                    | j                   }|6t        j                  j                  | j                  j
                  df      }n|j                  }t        j                  j                  || j                  f      }||fS )ar  Get fully-qualified parent path and prefix for this collection.

        Returns:
            Tuple[str, str]: Pair of

            * the fully-qualified (with database and project) path to the
              parent of this collection (will either be the database path
              or a document path).
            * the prefix to a document in this collection.
        	documents)r@   r   DOCUMENT_PATH_DELIMITERjoinr(   _database_string_document_pathr:   )r*   
parent_docr?   expected_prefixs       r-   _parent_infoz$BaseCollectionReference._parent_info   sr     [[
"::??..<K %33K"::??dgg@VWO++r/   c                p    |
t               }| j                  |      }t        j                  ||      }||fS )z+Shared setup for async / sync :method:`add`)rK   r>   r   make_retry_timeout_kwargs)r*   document_datarL   r   timeoutdocument_refr,   s          r-   	_prep_addz!BaseCollectionReference._prep_add   s<     "*K}}[133E7CV##r/   c                    t         r1   rB   )r*   rY   rL   r   rZ   s        r-   addzBaseCollectionReference.add   s
     "!r/   c                    | j                         \  }}|| j                  |dddid}t        j                  ||      }||fS )z6Shared setup for async / sync :method:`list_documents`Tfield_pathsN)r@   collection_id	page_sizeshow_missingmask)rV   r:   r   rX   )r*   rb   r   rZ   r@   _requestr,   s           r-   _prep_list_documentsz,BaseCollectionReference._prep_list_documents   sU     %%'	!WW"  #D)	
 33E7Cr/   c                    t         r1   rB   )r*   rb   r   rZ   s       r-   list_documentsz&BaseCollectionReference.list_documents   
     "!r/   c                >    | j                         j                         S r1   )rD   	recursiver9   s    r-   rl   z!BaseCollectionReference.recursive   s    {{}&&((r/   c                D    | j                         }|j                  |      S )a  Create a "select" query with this collection as parent.

        See
        :meth:`~google.cloud.firestore_v1.query.Query.select` for
        more information on this method.

        Args:
            field_paths (Iterable[str, ...]): An iterable of field paths
                (``.``-delimited list of field names) to use as a projection
                of document fields in the query results.

        Returns:
            :class:`~google.cloud.firestore_v1.query.Query`:
            A "projected" query.
        )rD   select)r*   r`   querys      r-   rn   zBaseCollectionReference.select   s      ||K((r/   filterc                  | j                         }|ri|rg|t        d      |dk(  rB|dk(  r=g }|D ]4  }t        |t              r| j	                  |      }|j                  |       6 |}|j                  |||      S |j                  |      S )a  Create a "where" query with this collection as parent.

        See
        :meth:`~google.cloud.firestore_v1.query.Query.where` for
        more information on this method.

        Args:
            field_path (str): A field path (``.``-delimited list of
                field names) for the field to filter on. Optional.
            op_string (str): A comparison operation in the form of a string.
                Acceptable values are ``<``, ``<=``, ``==``, ``>=``, ``>``,
                and ``in``. Optional.
            value (Any): The value to compare the field against in the filter.
                If ``value`` is :data:`None` or a NaN, then ``==`` is the only
                allowed operation.  If ``op_string`` is ``in``, ``value``
                must be a sequence of values. Optional.
            filter (class:`~google.cloud.firestore_v1.base_query.BaseFilter`): an instance of a Filter.
                Either a FieldFilter or a CompositeFilter.
        Returns:
            :class:`~google.cloud.firestore_v1.query.Query`:
            A filtered query.
        Raises:
            ValueError, if both the positional arguments (field_path, op_string, value)
                and the filter keyword argument are passed at the same time.
        zICan't pass in both the positional arguments and 'filter' at the same time__name__inrp   )rD   
ValueErrorr2   strr>   appendwhere)r*   
field_path	op_stringvaluerq   ro   wrapped_namesnames           r-   rx   zBaseCollectionReference.where   s    B )! _  Z'I,= "! /D!$,#}}T2!((.	/ &;;z9e<<;;f;--r/   c                H    | j                         } |j                  |fi |S )a  Create an "order by" query with this collection as parent.

        See
        :meth:`~google.cloud.firestore_v1.query.Query.order_by` for
        more information on this method.

        Args:
            field_path (str): A field path (``.``-delimited list of
                field names) on which to order the query results.
            kwargs (Dict[str, Any]): The keyword arguments to pass along
                to the query. The only supported keyword is ``direction``,
                see :meth:`~google.cloud.firestore_v1.query.Query.order_by`
                for more information.

        Returns:
            :class:`~google.cloud.firestore_v1.query.Query`:
            An "order by" query.
        )rD   order_by)r*   ry   r,   ro   s       r-   r   z BaseCollectionReference.order_by4  s%    & u~~j3F33r/   c                D    | j                         }|j                  |      S )a-  Create a limited query with this collection as parent.

        .. note::
           `limit` and `limit_to_last` are mutually exclusive.
           Setting `limit` will drop previously set `limit_to_last`.

        See
        :meth:`~google.cloud.firestore_v1.query.Query.limit` for
        more information on this method.

        Args:
            count (int): Maximum number of documents to return that match
                the query.

        Returns:
            :class:`~google.cloud.firestore_v1.query.Query`:
            A limited query.
        )rD   limitr*   countro   s      r-   r   zBaseCollectionReference.limitJ  s    & {{5!!r/   c                D    | j                         }|j                  |      S )aD  Create a limited to last query with this collection as parent.

        .. note::
           `limit` and `limit_to_last` are mutually exclusive.
           Setting `limit_to_last` will drop previously set `limit`.

        See
        :meth:`~google.cloud.firestore_v1.query.Query.limit_to_last`
        for more information on this method.

        Args:
            count (int): Maximum number of documents to return that
                match the query.
        Returns:
            :class:`~google.cloud.firestore_v1.query.Query`:
            A limited to last query.
        )rD   limit_to_lastr   s      r-   r   z%BaseCollectionReference.limit_to_last`  s     $ ""5))r/   c                D    | j                         }|j                  |      S )a  Skip to an offset in a query with this collection as parent.

        See
        :meth:`~google.cloud.firestore_v1.query.Query.offset` for
        more information on this method.

        Args:
            num_to_skip (int): The number of results to skip at the beginning
                of query results. (Must be non-negative.)

        Returns:
            :class:`~google.cloud.firestore_v1.query.Query`:
            An offset query.
        )rD   offset)r*   num_to_skipro   s      r-   r   zBaseCollectionReference.offsetu  s     ||K((r/   c                D    | j                         }|j                  |      S )a  Start query at a cursor with this collection as parent.

        See
        :meth:`~google.cloud.firestore_v1.query.Query.start_at` for
        more information on this method.

        Args:
            document_fields (Union[:class:`~google.cloud.firestore_v1.                document.DocumentSnapshot`, dict, list, tuple]):
                A document snapshot or a dictionary/list/tuple of fields
                representing a query results cursor. A cursor is a collection
                of values that represent a position in a query result set.

        Returns:
            :class:`~google.cloud.firestore_v1.query.Query`:
            A query with cursor.
        )rD   start_atr*   document_fieldsro   s      r-   r   z BaseCollectionReference.start_at  s    ( ~~o..r/   c                D    | j                         }|j                  |      S )a  Start query after a cursor with this collection as parent.

        See
        :meth:`~google.cloud.firestore_v1.query.Query.start_after` for
        more information on this method.

        Args:
            document_fields (Union[:class:`~google.cloud.firestore_v1.                document.DocumentSnapshot`, dict, list, tuple]):
                A document snapshot or a dictionary/list/tuple of fields
                representing a query results cursor. A cursor is a collection
                of values that represent a position in a query result set.

        Returns:
            :class:`~google.cloud.firestore_v1.query.Query`:
            A query with cursor.
        )rD   start_afterr   s      r-   r   z#BaseCollectionReference.start_after  s     (   11r/   c                D    | j                         }|j                  |      S )a  End query before a cursor with this collection as parent.

        See
        :meth:`~google.cloud.firestore_v1.query.Query.end_before` for
        more information on this method.

        Args:
            document_fields (Union[:class:`~google.cloud.firestore_v1.                document.DocumentSnapshot`, dict, list, tuple]):
                A document snapshot or a dictionary/list/tuple of fields
                representing a query results cursor. A cursor is a collection
                of values that represent a position in a query result set.

        Returns:
            :class:`~google.cloud.firestore_v1.query.Query`:
            A query with cursor.
        )rD   
end_beforer   s      r-   r   z"BaseCollectionReference.end_before  s     ( 00r/   c                D    | j                         }|j                  |      S )a  End query at a cursor with this collection as parent.

        See
        :meth:`~google.cloud.firestore_v1.query.Query.end_at` for
        more information on this method.

        Args:
            document_fields (Union[:class:`~google.cloud.firestore_v1.                document.DocumentSnapshot`, dict, list, tuple]):
                A document snapshot or a dictionary/list/tuple of fields
                representing a query results cursor. A cursor is a collection
                of values that represent a position in a query result set.

        Returns:
            :class:`~google.cloud.firestore_v1.query.Query`:
            A query with cursor.
        )rD   end_atr   s      r-   r   zBaseCollectionReference.end_at  s    ( ||O,,r/   c                V    | j                         }t        j                  ||      }||fS )z:Shared setup for async / sync :meth:`get` / :meth:`stream`)rD   r   rX   )r*   r   rZ   ro   r,   s        r-   _prep_get_or_streamz+BaseCollectionReference._prep_get_or_stream  s+     33E7Cf}r/   )explain_optionsc                   t         r1   rB   r*   transactionr   rZ   r   s        r-   getzBaseCollectionReference.get  s
     "!r/   c                   t         r1   rB   r   s        r-   streamzBaseCollectionReference.stream  rj   r/   c                    t         r1   rB   )r*   callbacks     r-   on_snapshotz#BaseCollectionReference.on_snapshot  rE   r/   c                B    | j                         j                  |      S )z
        Adds a count over the nested query.

        :type alias: str
        :param alias: (Optional) The alias for the count
        alias)rG   r   )r*   r   s     r-   r   zBaseCollectionReference.count  s!     &&(..U.;;r/   c                D    | j                         j                  ||      S )a  
        Adds a sum over the nested query.

        :type field_ref: Union[str, google.cloud.firestore_v1.field_path.FieldPath]
        :param field_ref: The field to aggregate across.

        :type alias: Optional[str]
        :param alias: Optional name of the field to store the result of the aggregation into.
            If not provided, Firestore will pick a default name following the format field_<incremental_id++>.

        r   )rG   sumr*   	field_refr   s      r-   r   zBaseCollectionReference.sum  s#     &&(,,Ye,DDr/   c                D    | j                         j                  ||      S )a  
        Adds an avg over the nested query.

        :type field_ref: Union[str, google.cloud.firestore_v1.field_path.FieldPath]
        :param field_ref: The field to aggregate across.

        :type alias: Optional[str]
        :param alias: Optional name of the field to store the result of the aggregation into.
            If not provided, Firestore will pick a default name following the format field_<incremental_id++>.
        r   )rG   avgr   s      r-   r   zBaseCollectionReference.avg  s#     &&(,,Ye,DDr/   distance_result_fielddistance_thresholdc               L    | j                         j                  ||||||      S )a  
        Finds the closest vector embeddings to the given query vector.

        Args:
            vector_field (str): An indexed vector field to search upon. Only documents which contain
                vectors whose dimensionality match the query_vector can be returned.
            query_vector(Union[Vector, Sequence[float]]): The query vector that we are searching on. Must be a vector of no more
                than 2048 dimensions.
            limit (int): The number of nearest neighbors to return. Must be a positive integer of no more than 1000.
            distance_measure (:class:`DistanceMeasure`): The Distance Measure to use.
            distance_result_field (Optional[str]):
                Name of the field to output the result of the vector distance calculation
            distance_threshold (Optional[float]):
                A threshold for which no less similar documents will be returned.

        Returns:
            :class`~firestore_v1.vector_query.VectorQuery`: the vector query.
        r   )rI   find_nearest)r*   vector_fieldquery_vectorr   distance_measurer   r   s          r-   r   z$BaseCollectionReference.find_nearest,  s7    8 !!#00"71 1 
 	
r/   )returnNone)r   r   )r   r   )r   r   r1   )rL   Optional[str]r   r   )r   zTuple[Any, str])NNN)
rY   dictrL   r   r   2retries.Retry | retries.AsyncRetry | object | NonerZ   Optional[float]r   zTuple[DocumentReference, dict])
rY   r   rL   r   r   r   rZ   r   r   z<Union[Tuple[Any, Any], Coroutine[Any, Any, Tuple[Any, Any]]])rb   Optional[int]r   r   rZ   r   r   zTuple[dict, dict])rb   r   r   r   rZ   r   r   zUUnion[Generator[DocumentReference, Any, Any], AsyncGenerator[DocumentReference, Any]])r`   zIterable[str]r   r   )ry   r   rz   r   r   r   )ry   rv   r   r   )r   intr   r   )r   r   )r   r   r   r   )r   z*Union[DocumentSnapshot, dict, list, tuple]r   r   )NN)r   r   rZ   r   r   zTuple[Any, dict])
r   Optional[Transaction]r   r   rZ   r   r   Optional[ExplainOptions]r   z\QueryResultsList[DocumentSnapshot] | Coroutine[Any, Any, QueryResultsList[DocumentSnapshot]])
r   r   r   r   rZ   r   r   r   r   zCStreamGenerator[DocumentSnapshot] | AsyncIterator[DocumentSnapshot])r   zstr | FieldPath)r   rv   r   zUnion[Vector, Sequence[float]]r   r   r   r   r   r   r   r   r   r   )%rs   
__module____qualname____doc__r.   r6   propertyr:   r@   rD   rG   rI   r>   rV   r\   r^   rg   ri   rl   rn   rx   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r/   r-   r!   r!   ;   s   2K
   3 3"""2,,2 &*DH#'$$ #$ B	$
 !$ 
($& &*DH#'"" #" B	"
 !" 
F" $(DH#'	  B !	
 
0 $(DH#'	" " B" !	"

"))* %)#'	3. 3.!3. !3. 
3.j4,",**)$/I/	/.2I2	2.1I1	1.-I-	-2 EI#'	A	 !	 
		 .2DH#'	" 59"*" B" !	" 2"	B" .2DH#'	" 59"*" B" !	" 2" 
M""<EE( 04.2#
#
 5#
 	#

 *#
  -#
 ,#
 
#
r/   r!   c                 D    dj                  d t        d      D              S )zGenerate a "random" automatically generated ID.

    Returns:
        str: A 20 character string composed of digits, uppercase and
        lowercase and letters.
     c              3  N   K   | ]  }t        j                  t                y wr1   )randomchoice_AUTO_ID_CHARS).0re   s     r-   	<genexpr>z_auto_id.<locals>.<genexpr>Z  s     DQ6==0Ds   #%   )rQ   ranger   r/   r-   rK   rK   R  s     77D%)DDDr/   c                |    |j                   j                  t        j                        d   }| j	                  |      S )zConvert Document resource to document ref.

    Args:
        collection_reference (google.api_core.page_iterator.GRPCIterator):
            iterator response
        item (dict): document resource
    r8   )r}   splitr   rP   r>   )collection_referenceitemrL   s      r-   _item_to_document_refr   ]  s2     ))//("B"BCBGK((55r/   )r   rv   )r   r   )3r   
__future__r   r   typingr   r   r   r   r   r	   r
   r   r   r   r   r   google.api_corer   retriesgoogle.cloud.firestore_v1r   $google.cloud.firestore_v1.base_queryr   *google.cloud.firestore_v1.base_aggregationr   'google.cloud.firestore_v1.base_documentr   +google.cloud.firestore_v1.base_vector_queryr   r   "google.cloud.firestore_v1.documentr   $google.cloud.firestore_v1.field_pathr   'google.cloud.firestore_v1.query_profiler   'google.cloud.firestore_v1.query_resultsr   *google.cloud.firestore_v1.stream_generatorr   %google.cloud.firestore_v1.transactionr    google.cloud.firestore_v1.vectorr   &google.cloud.firestore_v1.vector_queryr   r   r!   rK   r   r   r/   r-   <module>r      s}    O "     - . :OH E>FHJA7BQT
gi0 T
nE	6r/   