Ë
    V¼Sfì&  ã                  ó(  — d Z ddlmZ ddlZddlmZ ddl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 dd	lmZ dd
lmZ ddlmZ  G d„ de«      Z G d„ de«      Z G d„ de«      Z G d„ de«      Z G d„ de«      Z	 	 	 	 dd„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.
é    )ÚannotationsN)ÚABC)ÚListÚ	CoroutineÚUnionÚTupleÚ	GeneratorÚAnyÚAsyncGenerator)Úgapic_v1)Úretry)Ú	FieldPath)ÚRunAggregationQueryResponse)ÚStructuredAggregationQuery)Ú_helpersc                  ó    — e Zd ZdZddd„Zd„ Zy)ÚAggregationResulta  
    A class representing result from Aggregation Query
    :type alias: str
    :param alias: The alias for the aggregation.
    :type value: int
    :param value: The resulting value from the aggregation.
    :type read_time:
    :param value: The resulting read_time
    Nc                ó.   — || _         || _        || _        y ©N©ÚaliasÚvalueÚ	read_time)Úselfr   r   r   s       úiC:\Users\user\Documents\project_loop\venv\Lib\site-packages\google/cloud/firestore_v1/base_aggregation.pyÚ__init__zAggregationResult.__init__5   s   € ØˆŒ
ØˆŒ
Ø"ˆ�ó    c                óV   — d| j                   › d| j                  › d| j                  › d�S )Nz<Aggregation alias=z, value=z, readtime=ú>r   ©r   s    r   Ú__repr__zAggregationResult.__repr__:   s.   € Ø$ T§Z¡Z L°¸¿¹¸ÀKÐPT×P^ÑP^ÐO_Ð_`ÐaÐar   r   )r   Ústrr   Úint)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r!   © r   r   r   r   *   s   „ ñô#ó
br   r   c                  ó:   — e Zd Zddd„Zej
                  d„ «       Zy)ÚBaseAggregationNc                ó   — || _         y r   ©r   )r   r   s     r   r   zBaseAggregation.__init__?   s	   € Øˆ�
r   c                 ó   — y)ú4Convert this instance to the protobuf representationNr(   r    s    r   Ú_to_protobufzBaseAggregation._to_protobufB   ó   � r   r   ©r   ú
str | None)r$   r%   r&   r   ÚabcÚabstractmethodr/   r(   r   r   r*   r*   >   s#   „ ôð 	×ÑñCó ñCr   r*   c                  ó(   ‡ — e Zd Zddˆ fd„Zd„ Zˆ xZS )ÚCountAggregationc                ó.   •— t         t        | �  |¬«       y ©Nr,   )Úsuperr6   r   )r   r   Ú	__class__s     €r   r   zCountAggregation.__init__H   s   ø€ ÜÔ Ñ.°UÐ.Õ;r   c                ó–   — t        j                  «       }| j                  |_        t         j                  j                  «       |_        |S ©r.   )r   ÚAggregationr   ÚCountÚcount©r   Úaggregation_pbs     r   r/   zCountAggregation._to_protobufK   s9   € ä3×?Ñ?ÓAˆØ#Ÿz™zˆÔÜ9×EÑE×KÑKÓMˆÔØÐr   r   r1   ©r$   r%   r&   r   r/   Ú__classcell__©r:   s   @r   r6   r6   G   s   ø„ ö<ör   r6   c                  ó(   ‡ — e Zd Zddˆ fd„Zd„ Zˆ xZS )ÚSumAggregationc                ó|   •— t        |t        «      r|j                  «       }|| _        t        t
        | �  |¬«       y r8   )Ú
isinstancer   Úto_api_reprÚ	field_refr9   rF   r   ©r   rJ   r   r:   s      €r   r   zSumAggregation.__init__T   ó4   ø€ Ü�i¤Ô+à!×-Ñ-Ó/ˆIØ"ˆŒÜŒn˜dÑ,°5Ð,Õ9r   c                óà   — t        j                  «       }| j                  |_        t         j                  j                  «       |_        | j
                  |j                  j                  _        |S r<   )r   r=   r   ÚSumÚsumrJ   ÚfieldÚ
field_pathr@   s     r   r/   zSumAggregation._to_protobuf[   óQ   € ä3×?Ñ?ÓAˆØ#Ÿz™zˆÔÜ7×CÑC×GÑGÓIˆÔØ.2¯n©nˆ×Ñ× Ñ Ô+ØÐr   r   ©rJ   zstr | FieldPathr   r2   rB   rD   s   @r   rF   rF   S   ó   ø„ ö:ör   rF   c                  ó(   ‡ — e Zd Zddˆ fd„Zd„ Zˆ xZS )ÚAvgAggregationc                ó|   •— t        |t        «      r|j                  «       }|| _        t        t
        | �  |¬«       y r8   )rH   r   rI   rJ   r9   rV   r   rK   s      €r   r   zAvgAggregation.__init__e   rL   r   c                óà   — t        j                  «       }| j                  |_        t         j                  j                  «       |_        | j
                  |j                  j                  _        |S r<   )r   r=   r   ÚAvgÚavgrJ   rP   rQ   r@   s     r   r/   zAvgAggregation._to_protobufl   rR   r   r   rS   rB   rD   s   @r   rV   rV   d   rT   r   rV   c                ó>  — | j                   j                  j                  j                  «       D �cg c]`  }t	        || j                   j                  |   j
                  xs# | j                   j                  |   j                  | j                  ¬«      ‘Œb }}|S c c}w )Nr   )ÚresultÚaggregate_fieldsÚpbÚkeysr   Úinteger_valueÚdouble_valuer   )Úresponse_pbÚkeyÚresultss      r   Ú_query_response_to_resultre   u   s•   € ð ×%Ñ%×6Ñ6×9Ñ9×>Ñ>Ó@öð ô 	ØØ×$Ñ$×5Ñ5°cÑ:×HÑHò EØ×!Ñ!×2Ñ2°3Ñ7×DÑDØ!×+Ñ+ö		
ð€Gð ð €Nùòs   ±A%Bc                  ó:  — e Zd ZdZddd„Zed„ «       Zddd„Zddd„Zddd„Z	dd„Z
dd	„Zdd
„Z	 	 	 d	 	 	 	 	 dd„Zej                  dej"                  j$                  df	 	 	 	 	 dd„«       Zej                  dej"                  j$                  df	 	 	 	 	 dd„«       Zy)ÚBaseAggregationQueryz5Represents an aggregation query to the Firestore API.Nc                óP   — || _         || _        |j                  | _        g | _        y r   )Ú_nested_queryÚ_aliasÚ_parentÚ_collection_refÚ_aggregations)r   Únested_queryr   s      r   r   zBaseAggregationQuery.__init__ˆ   s'   € Ø)ˆÔØˆŒØ+×3Ñ3ˆÔØ46ˆÕr   c                ó.   — | j                   j                  S r   )rl   Ú_clientr    s    r   rp   zBaseAggregationQuery._clientŽ   s   € à×#Ñ#×+Ñ+Ð+r   c                óT   — t        |¬«      }| j                  j                  |«       | S )z4
        Adds a count over the nested query
        r,   )r6   rm   Úappend)r   r   Úcount_aggregations      r   r?   zBaseAggregationQuery.count’   s)   € ô -°5Ô9ÐØ×Ñ×!Ñ!Ð"3Ô4Øˆr   c                óV   — t        ||¬«      }| j                  j                  |«       | S )z2
        Adds a sum over the nested query
        r,   )rF   rm   rr   )r   rJ   r   Úsum_aggregations       r   rO   zBaseAggregationQuery.sumš   ó)   € ô )¨¸%Ô@ˆØ×Ñ×!Ñ! /Ô2Øˆr   c                óV   — t        ||¬«      }| j                  j                  |«       | S )z3
        Adds an avg over the nested query
        r,   )rV   rm   rr   )r   rJ   r   Úavg_aggregations       r   rZ   zBaseAggregationQuery.avg¢   rv   r   c                ó:   — | j                   j                  |«       y)zì
        Adds an aggregation operation to the nested query

        :type aggregation: :class:`google.cloud.firestore_v1.aggregation.BaseAggregation`
        :param aggregation: An aggregation operation, e.g. a CountAggregation
        N)rm   rr   )r   Úaggregations     r   Úadd_aggregationz$BaseAggregationQuery.add_aggregationª   s   € ð 	×Ñ×!Ñ! +Õ.r   c                ó:   — | j                   j                  |«       y)z¡
        Adds a list of aggregations to the nested query

        :type aggregations: list
        :param aggregations: a list of aggregation operations
        N)rm   Úextend)r   Úaggregationss     r   Úadd_aggregationsz%BaseAggregationQuery.add_aggregations³   s   € ð 	×Ñ×!Ñ! ,Õ/r   c                óÐ   — t        «       }| j                  j                  «       |_        | j                  D ]-  }|j                  «       }|j
                  j                  |«       Œ/ |S r   )r   ri   r/   Ústructured_queryrm   r~   rr   )r   r^   rz   rA   s       r   r/   z!BaseAggregationQuery._to_protobuf¼   s]   € Ü'Ó)ˆØ"×0Ñ0×=Ñ=Ó?ˆÔà×-Ñ-ò 	3ˆKØ(×5Ñ5Ó7ˆNØ�O‰O×"Ñ" >Õ2ð	3ð ˆ	r   c                ó¾   — | j                   j                  «       \  }}|| j                  «       t        j                  |«      dœ}t        j
                  ||«      }||fS )N)ÚparentÚstructured_aggregation_queryÚtransaction)rl   Ú_parent_infor/   r   Úget_transaction_idÚmake_retry_timeout_kwargs)r   r…   r   ÚtimeoutÚparent_pathÚexpected_prefixÚrequestÚkwargss           r   Ú_prep_streamz!BaseAggregationQuery._prep_streamÅ   s_   € ð (,×';Ñ';×'HÑ'HÓ'JÑ$ˆ�_à!Ø,0×,=Ñ,=Ó,?Ü#×6Ñ6°{ÓCñ
ˆô
 ×3Ñ3°E¸7ÓCˆà˜ˆÐr   c                 ó   — y)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.

        Returns:
            list: The aggregation query results

        Nr(   ©r   r…   r   r‰   s       r   ÚgetzBaseAggregationQuery.getÕ   r0   r   c                 ó   — y)a}  Runs the aggregation query.

        This sends a``RunAggregationQuery`` RPC and returns an iterator 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.

        Returns:
            list: The aggregation query results

        Nr(   r�   s       r   ÚstreamzBaseAggregationQuery.streamó   r0   r   r   )r   r2   ÚreturnÚNoner1   rS   )rz   r*   r”   r•   )r~   zList[BaseAggregation]r”   r•   )r”   r   )NNN)r   ú:Union[retries.Retry, None, gapic_v1.method._MethodDefault]r‰   úfloat | Noner”   zTuple[dict, dict])r   r–   r‰   r—   r”   zFList[AggregationResult] | Coroutine[Any, Any, List[AggregationResult]])r   r–   r‰   r—   r”   z]Generator[List[AggregationResult], Any, None] | AsyncGenerator[List[AggregationResult], None])r$   r%   r&   r'   r   Úpropertyrp   r?   rO   rZ   r{   r   r/   rŽ   r3   r4   r   ÚmethodÚDEFAULTr‘   r“   r(   r   r   rg   rg   …   s
  „ Ù?ô7ð ñ,ó ð,ôôôó/ó0óð ØLPØ $ð	ð Jðð ð	ð
 
óð  	×Ñð ð �O‰O×#Ñ#Ø $ðð
ðð ðð 
Pòó ðð: 	×Ñð ð �O‰O×#Ñ#Ø $ðð
ðð ðð	8òó ñr   rg   )rb   r   r”   zList[AggregationResult]) r'   Ú
__future__r   r3   r   Útypingr   r   r   r   r	   r
   r   Úgoogle.api_corer   r   ÚretriesÚ$google.cloud.firestore_v1.field_pathr   Úgoogle.cloud.firestore_v1.typesr   r   Úgoogle.cloud.firestore_v1r   Úobjectr   r*   r6   rF   rV   re   rg   r(   r   r   ú<module>r£      s—   ðñõ #ã 
õ ç P× PÑ På $Ý ,õ ;Ý GÝ FÝ .ôb˜ô bô(C�cô Cô	�ô 	ô�_ô ô"�_ô ð"Ø,ðàóô M˜3õ Mr   