
    Ѯh-                        d 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mZmZmZmZ ddlmZmZ ddlmZ erdd	lmZ dd
lmZ ddlmZ ddlmZ  G d deej@                           Z!y)zHClasses for representing collections for the Google Cloud Firestore API.    )annotations)TYPE_CHECKINGAnyAsyncGeneratorOptionalTuple)gapic_v1)retry_async)async_aggregationasync_documentasync_queryasync_vector_querytransaction)BaseCollectionReference_item_to_document_ref)DocumentReference)AsyncStreamGenerator)DocumentSnapshot)ExplainOptions)QueryResultsListc                      e Zd ZdZd fdZddZddZddZddZde	j                  j                  df	 	 	 	 	 	 	 	 	 ddZ	 d	 	 	 d fd	Zde	j                  j                  df	 	 	 	 	 	 	 dd
Zde	j                  j                  dfdd	 	 	 	 	 	 	 	 	 ddZde	j                  j                  dfdd	 	 	 	 	 	 	 	 	 ddZ xZS )AsyncCollectionReferencea  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        t        | 
  |i | y N)superr   __init__)selfpathkwargs	__class__s      |/home/www/academy-backend.kofcorporation.com/venv/lib/python3.12/site-packages/google/cloud/firestore_v1/async_collection.pyr   z!AsyncCollectionReference.__init__E   s    &6GG    c                ,    t        j                  |       S )zeQuery factory.

        Returns:
            :class:`~google.cloud.firestore_v1.query.Query`
        )r   
AsyncQueryr   s    r!   _queryzAsyncCollectionReference._queryH   s     %%d++r"   c                H    t        j                  | j                               S )zAsyncAggregationQuery factory.

        Returns:
            :class:`~google.cloud.firestore_v1.async_aggregation.AsyncAggregationQuery
        )r   AsyncAggregationQueryr&   r%   s    r!   _aggregation_queryz+AsyncCollectionReference._aggregation_queryP   s     !66t{{}EEr"   c                H    t        j                  | j                               S )zAsyncVectorQuery factory.

        Returns:
            :class:`~google.cloud.firestore_v1.async_vector_query.AsyncVectorQuery`
        )r   AsyncVectorQueryr&   r%   s    r!   _vector_queryz&AsyncCollectionReference._vector_queryX   s     "224;;=AAr"   c               n   K   | j                         j                  |      2 3 d {   }| 7 
6 y wr   )r&   	_chunkify)r   
chunk_sizepages      r!   r.   z"AsyncCollectionReference._chunkify`   s4     ++-11*= 	 	$J	=s    5313535Nc                   K   | j                  ||||      \  }} |j                  |fi | d{   }|j                  |fS 7 w)a   Create a document in the Firestore database with the provided data.

        Args:
            document_data (dict): Property names and values to use for
                creating the document.
            document_id (Optional[str]): The document identifier within the
                current collection. If not provided, an ID will be
                automatically assigned by the server (the assigned ID will be
                a random 20 character string composed of digits,
                uppercase and lowercase letters).
            retry (google.api_core.retry.Retry): Designation of what errors, if any,
                should be retried.  Defaults to a system-specified policy.
            timeout (float): The timeout for this request.  Defaults to a
                system-specified value.

        Returns:
            Tuple[:class:`google.protobuf.timestamp_pb2.Timestamp`,                 :class:`~google.cloud.firestore_v1.async_document.AsyncDocumentReference`]:
                Pair of

                * The ``update_time`` when the document was created/overwritten.
                * A document reference for the created document.

        Raises:
            :class:`google.cloud.exceptions.Conflict`:
                If ``document_id`` is provided and the document already exists.
        N)	_prep_addcreateupdate_time)r   document_datadocument_idretrytimeoutdocument_refr   write_results           r!   addzAsyncCollectionReference.addd   s[     D  $~~	 
f 1\00I&II''55 Js   .AAAc                *    t         t        |   |      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.async_document.AsyncDocumentReference`:
            The child document.
        )r   r   document)r   r6   r    s     r!   r=   z!AsyncCollectionReference.document   s     -t=kJJr"   c                 K   | j                  |||      \  }} | j                  j                  j                  d|| j                  j                  d| d{   }|2 3 d{   }t        | |       7 7 6 yw)a`  List all subdocuments of the current collection.

        Args:
            page_size (Optional[int]]): The maximum number of documents
                in each page of results from this request. Non-positive values
                are ignored. Defaults to a sensible value set by the API.
            retry (google.api_core.retry.Retry): Designation of what errors, if any,
                should be retried.  Defaults to a system-specified policy.
            timeout (float): The timeout for this request.  Defaults to a
                system-specified value.

        Returns:
            Sequence[:class:`~google.cloud.firestore_v1.collection.DocumentReference`]:
                iterator of subdocuments of the current collection. If the
                collection does not exist at the time of `snapshot`, the
                iterator will be empty
        )requestmetadataN )_prep_list_documents_client_firestore_apilist_documents_rpc_metadatar   )r   	page_sizer7   r8   r?   r   iteratoris           r!   rE   z'AsyncCollectionReference.list_documents   s     . 33IugNC44CC 
\\//
 
 

   	1 	1!'a00

	1xs6   AA?A9A? A=$A;%A=(A?;A==A?)explain_optionsc               ~   K   | j                  ||      \  }}|||d<    |j                  dd|i| d{   S 7 w)a  Read the documents in this collection.

        This sends a ``RunQuery`` RPC and returns a list of documents
        returned in the stream of ``RunQueryResponse`` messages.

        Args:
            transaction
                (Optional[:class:`~google.cloud.firestore_v1.transaction.Transaction`]):
                An existing transaction that this query will run in.
            retry (Optional[google.api_core.retry.Retry]): Designation of what
                errors, if any, should be retried.  Defaults to a
                system-specified policy.
            timeout (Otional[float]): The timeout for this request.  Defaults
                to a system-specified value.
            explain_options
                (Optional[:class:`~google.cloud.firestore_v1.query_profile.ExplainOptions`]):
                Options to enable query profiling for this query. When set,
                explain_metrics will be available on the returned generator.

        If a ``transaction`` is used and it already has write operations added,
        this method cannot be used (i.e. read-after-write is not allowed).

        Returns:
            QueryResultsList[DocumentSnapshot]:
            The documents in this collection that match the query.
        NrJ   r   rA   )_prep_get_or_streamgetr   r   r7   r8   rJ   queryr   s          r!   rM   zAsyncCollectionReference.get   sO     D 00@v&(7F$%UYYA;A&AAAAs   4=;=c               b    | j                  ||      \  }}|r||d<    |j                  dd|i|S )a%  Read the documents in this collection.

        This sends a ``RunQuery`` RPC and then returns a generator which
        consumes each document returned in the stream of ``RunQueryResponse``
        messages.

        .. note::

           The underlying stream of responses will time out after
           the ``max_rpc_timeout_millis`` value set in the GAPIC
           client configuration for the ``RunQuery`` API.  Snapshots
           not consumed from the iterator before that point will be lost.

        If a ``transaction`` is used and it already has write operations
        added, this method cannot be used (i.e. read-after-write is not
        allowed).

        Args:
            transaction (Optional[:class:`~google.cloud.firestore_v1.transaction.                Transaction`]):
                An existing transaction that the query will run in.
            retry (Optional[google.api_core.retry.Retry]): Designation of what
                errors, if any, should be retried.  Defaults to a
                system-specified policy.
            timeout (Optional[float]): The timeout for this request. Defaults
                to a system-specified value.
            explain_options
                (Optional[:class:`~google.cloud.firestore_v1.query_profile.ExplainOptions`]):
                Options to enable query profiling for this query. When set,
                explain_metrics will be available on the returned generator.

        Returns:
            `AsyncStreamGenerator[DocumentSnapshot]`: A generator of the query
            results.
        rJ   r   rA   )rL   streamrN   s          r!   rQ   zAsyncCollectionReference.stream   sB    V 00@v(7F$%u||>>v>>r"   )returnNone)rR   zasync_query.AsyncQuery)rR   z'async_aggregation.AsyncAggregationQuery)rR   z#async_vector_query.AsyncVectorQuery)r/   int)
r5   dictr6   
str | Noner7   "retries.AsyncRetry | object | Noner8   float | NonerR   zTuple[Any, Any]r   )r6   rV   rR   z%async_document.AsyncDocumentReference)rG   z
int | Noner7   rW   r8   rX   rR   z'AsyncGenerator[DocumentReference, None])
r   !Optional[transaction.Transaction]r7   rW   r8   Optional[float]rJ   Optional[ExplainOptions]rR   z"QueryResultsList[DocumentSnapshot])
r   rY   r7   rW   r8   rZ   rJ   r[   rR   z&AsyncStreamGenerator[DocumentSnapshot])__name__
__module____qualname____doc__r   r&   r)   r,   r.   r	   methodDEFAULTr;   r=   rE   rM   rQ   __classcell__)r    s   @r!   r   r   +   s}   2H,FB #'4<OO4K4K $)6)6  )6 2	)6
 )6 
)6X )-K%K	.K& !%4<OO4K4K $	11 21 	1
 
11F :>4<OO4K4K#'	&B 59&B6&B 2&B !	&B 2&B 
,&BT :>4<OO4K4K#'	/? 59/?6/? 2/? !	/? 2/? 
0/?r"   r   N)"r_   
__future__r   typingr   r   r   r   r   google.api_corer	   r
   retriesgoogle.cloud.firestore_v1r   r   r   r   r   )google.cloud.firestore_v1.base_collectionr   r   "google.cloud.firestore_v1.documentr   0google.cloud.firestore_v1.async_stream_generatorr   'google.cloud.firestore_v1.base_documentr   'google.cloud.firestore_v1.query_profiler   'google.cloud.firestore_v1.query_resultsr   r$   r   rA   r"   r!   <module>rn      sX    O " F F $ 2  AUHFHm?6{7M7MN m?r"   