Ë
    ö%9j”+  ã                  óº   — 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mZ ddl
mZ ddlmZmZmZ ddlmZ ddlmZ erdd	lZdd
lmZ ddlmZmZ  G d„ de«      Zy	)aU  Classes for representing aggregation queries for the Google Cloud Firestore API.

A :class:`~google.cloud.firestore_v1.aggregation.AggregationQuery` can be created directly from
a :class:`~google.cloud.firestore_v1.collection.Collection` and that can be
a more common way to create an aggregation query than direct usage of the constructor.
é    )Úannotations)ÚTYPE_CHECKINGÚAnyÚ	GeneratorÚListÚOptionalÚUnion)Ú
exceptionsÚgapic_v1)Úretry)ÚAggregationResultÚBaseAggregationQueryÚ_query_response_to_result)ÚQueryResultsList)ÚStreamGeneratorN)Útransaction)ÚExplainMetricsÚExplainOptionsc                  ó2  ‡ — e Zd ZdZ	 	 d
ˆ fd„Zdej                  j                  dfdddœ	 	 	 	 	 	 	 	 	 dd„Z	 dd„Z	d„ Z
dej                  j                  dddf	 	 	 	 	 	 	 	 	 	 	 dd„Zdej                  j                  dfdddœ	 	 	 	 	 	 	 	 	 	 	 dd	„Zˆ xZS )ÚAggregationQueryz5Represents an aggregation query to the Firestore API.c                ó,   •— t         t        | �  |«       y )N)Úsuperr   Ú__init__)ÚselfÚnested_queryÚ	__class__s     €úa/var/www/html/truck-me/venv/lib/python3.12/site-packages/google/cloud/firestore_v1/aggregation.pyr   zAggregationQuery.__init__0   s   ø€ ô 	Ô Ñ.¨|Õ<ó    N)Úexplain_optionsÚ	read_timec               óŒ   — d}| j                  |||||¬«      }t        |«      }|€d}n|j                  «       }t        |||«      S )aP  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.
            read_time (Optional[datetime.datetime]): If set, reads documents as they were at the given
                time. This must be a timestamp within the past one hour, or if Point-in-Time Recovery
                is enabled, can additionally be a whole minute timestamp within the past 7 days. If no
                timezone is specified in the :class:`datetime.datetime` object, it is assumed to be UTC.

        Returns:
            QueryResultsList[AggregationResult]: The aggregation query results.

        N©r   r   Útimeoutr   r    )ÚstreamÚlistÚget_explain_metricsr   )	r   r   r   r#   r   r    Úexplain_metricsÚresultÚresult_lists	            r   ÚgetzAggregationQuery.get6   s_   € ðJ 26ˆà—‘Ø#ØØØ+Øð ó 
ˆô ˜6“lˆàÐ"Ø"‰Oà$×8Ñ8Ó:ˆOä ¨_¸oÓNÐNr   c                ó¬   — | j                  |||||«      \  }} | j                  j                  j                  d|| j                  j                  dœ|¤ŽS )ú!Helper method for :meth:`stream`.)ÚrequestÚmetadata© )Ú_prep_streamÚ_clientÚ_firestore_apiÚrun_aggregation_queryÚ_rpc_metadata)r   r   r   r#   r   r    r-   Úkwargss           r   Ú_get_stream_iteratorz%AggregationQuery._get_stream_iteratorm   sh   € ð ×+Ñ+ØØØØØó
‰ˆ�ð Aˆt�|‰|×*Ñ*×@Ñ@ð 
ØØ—\‘\×/Ñ/ñ
ð ñ
ð 	
r   c                óÒ   — |€e|t         j                  j                  u r8| j                  j                  j
                  }|j                  }|j                  }|j                  |«      S y)r,   F)	r   ÚmethodÚDEFAULTr1   r2   Ú
_transportr3   Ú_retryÚ
_predicate)r   Úexcr   r   Ú	transportÚgapic_callables         r   Ú_retry_query_after_exceptionz-AggregationQuery._retry_query_after_exception   sY   € àÐØœŸ™×/Ñ/Ñ/Ø ŸL™L×7Ñ7×BÑB�	Ø!*×!@Ñ!@�Ø&×-Ñ-�Ø×#Ñ# CÓ(Ð(àr   c              #  óH  K  — d}| j                  |||||«      }	 	 t        |d«      }|€	 |S |€|j
                  r|j
                  }t        |«      }
|
r|
–— Œ># t        j                  $ r3}	| j	                  |	||«      r| j                  |||||«      }Y d}	~	Œ‚ d}	~	ww xY w­w)aI  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 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 (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.
            read_time (Optional[datetime.datetime]): If set, reads documents as they were at the given
                time. This must be a timestamp within the past one hour, or if Point-in-Time Recovery
                is enabled, can additionally be a whole minute timestamp within the past 7 days. If no
                timezone is specified in the :class:`datetime.datetime` object, it is assumed to be UTC.

        Yields:
            List[AggregationResult]:
            The result of aggregations of this query.

        Returns:
            (Optional[google.cloud.firestore_v1.types.query_profile.ExplainMetrtics]):
            The results of query profiling, if received from the service.

        N)r6   Únextr
   ÚGoogleAPICallErrorr@   r'   r   )r   r   r   r#   r   r    ÚmetricsÚresponse_iteratorÚresponser=   r(   s              r   Ú_make_streamzAggregationQuery._make_streamŠ   sÙ   è ø€ ðT *.ˆà ×5Ñ5ØØØØØó
Ðð ðÜÐ 1°4Ó8�ð ÐØð ˆð ˆ 8×#;Ò#;Ø"×2Ñ2�ä.¨xÓ8ˆFÙØ’ð1 øô ×0Ñ0ò Ø×4Ñ4°S¸%ÀÔMØ(,×(AÑ(AØ#ØØØ'Ø!ó)Ð%ô àûðüs3   ‚B"œA ¨1B"ÁBÁ,(BÂB"ÂBÂBÂB"c               óF   — | 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 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 (Optinal[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.
            read_time (Optional[datetime.datetime]): If set, reads documents as they were at the given
                time. This must be a timestamp within the past one hour, or if Point-in-Time Recovery
                is enabled, can additionally be a whole minute timestamp within the past 7 days. If no
                timezone is specified in the :class:`datetime.datetime` object, it is assumed to be UTC.

        Returns:
            `StreamGenerator[List[AggregationResult]]`:
            A generator of the query results.
        r"   )rG   r   )r   r   r   r#   r   r    Úinner_generators          r   r$   zAggregationQuery.streamÙ   s8   € ðL ×+Ñ+Ø#ØØØ+Øð ,ó 
ˆô ˜°Ó@Ð@r   )ÚreturnÚNone)
r   ú"Union[retries.Retry, None, object]r#   zfloat | Noner   úOptional[ExplainOptions]r    úOptional[datetime.datetime]rJ   z#QueryResultsList[AggregationResult])NN)r   z!Optional[transaction.Transaction]r   rL   r#   úOptional[float]r   rM   r    rN   rJ   zAGenerator[List[AggregationResult], Any, Optional[ExplainMetrics]])r   z#Optional['transaction.Transaction']r   rL   r#   rO   r   rM   r    rN   rJ   z(StreamGenerator[List[AggregationResult]])Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r8   r9   r*   r6   r@   rG   r$   Ú__classcell__)r   s   @r   r   r   -   sT  ø„ Ù?ð=ð 
õ=ð Ø4<·O±O×4KÑ4KØ $ð	5Oð 59Ø15ñ5Oð 2ð5Oð ð	5Oð 2ð5Oð /ð5Oð 
-ó5Oðp LPó
ò$	ð :>Ø4<·O±O×4KÑ4KØ#'Ø48Ø15ðMà6ðMð 2ðMð !ð	Mð
 2ðMð /ðMð 
KóMðb <@Ø4<·O±O×4KÑ4KØ#'ð	-Að 59Ø15ñ-Aà8ð-Að 2ð-Að !ð	-Að 2ð-Að /ð-Að 
2÷-Ar   r   )rS   Ú
__future__r   Útypingr   r   r   r   r   r	   Úgoogle.api_corer
   r   r   ÚretriesÚ*google.cloud.firestore_v1.base_aggregationr   r   r   Ú'google.cloud.firestore_v1.query_resultsr   Ú*google.cloud.firestore_v1.stream_generatorr   ÚdatetimeÚgoogle.cloud.firestore_v1r   Ú'google.cloud.firestore_v1.query_profiler   r   r   r/   r   r   ú<module>r_      sM   ðñõ #ç G× Gç 0Ý ,÷ñ õ
 EÝ Fñ Ûå5ßVôYAÐ+õ YAr   