
    Ѯh!                        d Z ddlmZ ddl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 ddl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mZ ddlmc mc mc mZ   G d de      Z!y)aq  Classes for representing Async aggregation queries for the Google Cloud Firestore API.

A :class:`~google.cloud.firestore_v1.async_aggregation.AsyncAggregationQuery` can be created directly from
a :class:`~google.cloud.firestore_v1.async_collection.AsyncCollection` and that can be
a more common way to create an aggregation query than direct usage of the constructor.
    )annotations)TYPE_CHECKINGAnyAsyncGeneratorListOptionalUnion)gapic_v1)retry_async)transaction)AsyncStreamGenerator)BaseAggregationQuery_query_response_to_result)QueryResultsList)AggregationResult)ExplainMetricsExplainOptionsNc                      e Zd ZdZ	 	 d fdZdej                  j                  dfdd	 	 	 	 	 	 	 d	dZdej                  j                  ddf	 	 	 	 	 	 	 	 	 d
dZ	dej                  j                  dfdd	 	 	 	 	 	 	 	 	 ddZ
 xZS )AsyncAggregationQueryz5Represents an aggregation query to the Firestore API.c                ,    t         t        |   |       y )N)superr   __init__)selfnested_query	__class__s     }/home/www/academy-backend.kofcorporation.com/venv/lib/python3.12/site-packages/google/cloud/firestore_v1/async_aggregation.pyr   zAsyncAggregationQuery.__init__-   s     	#T3LA    N)explain_optionsc               :  K   d}| j                  ||||      }	 |2 cg c3 d{   }|7 6 nc c}w }}|d}n|j                          d{  7  }|j                          d{  7   n# |j                          d{  7   w xY wt        |||      S w)a  Runs the aggregation query.

        This sends a ``RunAggregationQuery`` RPC and returns a list of aggregation results in the stream of ``RunAggregationQueryResponse`` messages.

        Args:
            transaction
                (Optional[:class:`~google.cloud.firestore_v1.transaction.Transaction`]):
                An existing transaction that this query will run in.
                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).
            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.
            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:
            QueryResultsList[List[AggregationResult]]: The aggregation query results.

        Nr   retrytimeoutr   )streamget_explain_metricsacloser   )	r   r   r!   r"   r   explain_metricsstream_resultaggregationresults	            r   getzAsyncAggregationQuery.get3   s     @ 26#+	 $ 
	);HIIKkIIIFI&"&(5(I(I(K"K"K&&(((-&&(((IIsa   BA0 1/-
/1/1 A0 AA0 B)A,*B0BBBBc               F  K   | j                  ||||      \  }} | j                  j                  j                  d|| j                  j                  d| d{   }|2 3 d{   }t        |      }	|	r|	 |j                  s(|j                  }
|
 :7 @7 76 yw)a	  Internal method for stream(). Runs the aggregation query.

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

        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.

        Yields:
            List[AggregationResult] | query_profile_pb.ExplainMetrics:
            The result of aggregations of this query. Query results will be
            yielded as `List[AggregationResult]`. When the result contains
            returned explain metrics, yield `query_profile_pb.ExplainMetrics`
            individually.
        )requestmetadataN )_prep_stream_client_firestore_apirun_aggregation_query_rpc_metadatar   r&   )r   r   r!   r"   r   r,   kwargsresponse_iteratorresponser)   metricss              r   _make_streamz"AsyncAggregationQuery._make_streamg   s     L ++	
 #T$,,"="="S"S #
\\//#
 #
 
 0 	 	(.x8F''"22
	/s<   AB!BB!!B%B&B)B!	B!BB!c               D    | j                  ||||      }t        ||      S )a  Runs the aggregation query.

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

        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[List[AggregationResult]]`:
                A generator of the query results.
        r    )r8   r   )r   r   r!   r"   r   inner_generators         r   r#   zAsyncAggregationQuery.stream   s5    H ++#+	 , 
 $O_EEr   )returnNone)r!   z'Union[retries.AsyncRetry, None, object]r"   zfloat | Noner   Optional[ExplainOptions]r;   z)QueryResultsList[List[AggregationResult]])
r   !Optional[transaction.Transaction]r!   "retries.AsyncRetry | object | Noner"   Optional[float]r   r=   r;   zNAsyncGenerator[List[AggregationResult] | query_profile_pb.ExplainMetrics, Any])
r   r>   r!   r?   r"   r@   r   r=   r;   z-AsyncStreamGenerator[List[AggregationResult]])__name__
__module____qualname____doc__r   r
   methodDEFAULTr*   r8   r#   __classcell__)r   s   @r   r   r   *   s   ?B 
B 9A9P9P $	2J 592J 72J 	2J 22J 
32Jl :>4<OO4K4K#'48:6: 2: !	:
 2: 
X:| :>4<OO4K4K#'	*F 59*F6*F 2*F !	*F 2*F 
7*Fr   r   )"rD   
__future__r   typingr   r   r   r   r   r	   google.api_corer
   r   retriesgoogle.cloud.firestore_v1r   0google.cloud.firestore_v1.async_stream_generatorr   *google.cloud.firestore_v1.base_aggregationr   r   'google.cloud.firestore_v1.query_resultsr   r   'google.cloud.firestore_v1.query_profiler   r   -google.cloud.firestore_v1.types.query_profilecloudfirestore_v1typesquery_profilequery_profile_pbr   r.   r   r   <module>rW      sL    # L L $ 2 1 Q ELVLLcF0 cFr   