o
    }l~i,                     @  s  d Z ddlm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 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 erddl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d
lmZ+ ddl,m-Z- ddl.m/Z/ ddl0m1Z1 ddl2m3Z3 ddl4m5Z5 ddlm6Z6 G dd dZ7ede7dZ8G dd de
e8 Z9G d d! d!e9e8 e	e8 Z:G d"d# d#e9e8 ee8 Z;G d$d% d%e9e8 ee8 Z<dS )&z
.. warning::
    **Preview API**: Firestore Pipelines is currently in preview and is
    subject to potential breaking changes in future releases.
    )annotations)AnyAsyncIterableAsyncIteratorIterableIteratorListGenericMutableMappingTypeTypeVarTYPE_CHECKING)_helpers)get_nested_value)	FieldPath)ExplainStats)QueryExplainError)ExecutePipelineRequest)ValueN)AsyncClient)Client)
BaseClient)AsyncTransaction)Transaction)BaseDocumentReference)	Timestamp)ExecutePipelineResponse)Vector)AsyncPipeline)_BasePipeline)Pipeline)Constant)PipelineExplainOptionsc                   @  s   e Zd ZdZ				d+d,ddZdd Zed-ddZed.ddZed/ddZ	ed/ddZ
ed0ddZd1d!d"Zd2d$d%Zd3d)d*ZdS )4PipelineResultz
    Contains data read from a Firestore Pipeline. The data can be extracted with
    the `data()` or `get()` methods.

    If the PipelineResult represents a non-document result `ref` may be `None`.
    Nclientr   	fields_pbMutableMapping[str, ValueProto]refBaseDocumentReference | Noneexecution_timeTimestamp | Nonecreate_timeupdate_timec                 C  s(   || _ || _|| _|| _|| _|| _dS )ah  
        PipelineResult should be returned from `pipeline.execute()`, not constructed manually.

        Args:
            client: The Firestore client instance.
            fields_pb: A map of field names to their protobuf Value representations.
            ref: The DocumentReference or AsyncDocumentReference if this result corresponds to a document.
            execution_time: The time at which the pipeline execution producing this result occurred.
            create_time: The creation time of the document, if applicable.
            update_time: The last update time of the document, if applicable.
        N)_client
_fields_pb_ref_execution_time_create_time_update_time)selfr$   r%   r'   r)   r+   r,    r4   p/var/www/newdalilibackend/backend/venv/lib/python3.10/site-packages/google/cloud/firestore_v1/pipeline_result.py__init__E   s   
zPipelineResult.__init__c                 C  s   t | j d|   dS )Nz(data=))type__name__datar3   r4   r4   r5   __repr__`   s   zPipelineResult.__repr__returnc                 C     | j S )z`
        The `BaseDocumentReference` if this result represents a document, else `None`.
        )r/   r;   r4   r4   r5   r'   c   s   zPipelineResult.ref
str | Nonec                 C  s   | j r| j jS dS )zIThe ID of the document if this result represents a document, else `None`.N)r/   idr;   r4   r4   r5   r@   j   s   zPipelineResult.idc                 C  r>   )z<The creation time of the document. `None` if not applicable.)r1   r;   r4   r4   r5   r+   o      zPipelineResult.create_timec                 C  r>   )z?The last update time of the document. `None` if not applicable.)r2   r;   r4   r4   r5   r,   t   rA   zPipelineResult.update_timer   c                 C  s   | j du r	td| j S )z
        The time at which the pipeline producing this result was executed.

        Raise:
            ValueError: if not set
        Nz6'execution_time' is expected to exist, but it is None.)r0   
ValueErrorr;   r4   r4   r5   r)   y   s   
zPipelineResult.execution_timeotherobjectboolc                 C  s&   t |tstS | j|jko| j|jkS )a  
        Compares this `PipelineResult` to another object for equality.

        Two `PipelineResult` instances are considered equal if their document
        references (if any) are equal and their underlying field data
        (protobuf representation) is identical.
        )
isinstancer#   NotImplementedr/   r.   )r3   rC   r4   r4   r5   __eq__   s   
zPipelineResult.__eq__dict | 'Vector' | Nonec                 C  s   | j du rdS t| j | jS )z
        Retrieves all fields in the result.

        Returns:
            The data in dictionary format, or `None` if the document doesn't exist.
        N)r.   r   decode_dictr-   r;   r4   r4   r5   r:      s   
zPipelineResult.data
field_pathstr | FieldPathr   c                 C  s0   t |tr|n| }t|| j}t|| jS )a  
        Retrieves the field specified by `field_path`.

        Args:
            field_path: The field path (e.g. 'foo' or 'foo.bar') to a specific field.

        Returns:
            The data at the specified field location, decoded to Python types.
        )rF   strto_api_reprr   r.   r   decode_valuer-   )r3   rK   str_pathvaluer4   r4   r5   get   s   zPipelineResult.get)NNNN)r$   r   r%   r&   r'   r(   r)   r*   r+   r*   r,   r*   )r=   r(   )r=   r?   )r=   r*   )r=   r   )rC   rD   r=   rE   )r=   rI   )rK   rL   r=   r   )r9   
__module____qualname____doc__r6   r<   propertyr'   r@   r+   r,   r)   rH   r:   rR   r4   r4   r4   r5   r#   =   s*    

r#   T)boundc                   @  s<   e Zd ZdZdddZedddZdddZd ddZdS )!_PipelineResultContainerzLBase class to hold shared attributes for PipelineSnapshot and PipelineStreamreturn_typeType[T]pipelinePipeline | AsyncPipelinetransaction%Transaction | AsyncTransaction | None	read_timedatetime.datetime | Noneexplain_optionsPipelineExplainOptions | Noneadditional_optionsdict[str, Constant | Value]c                 C  sP   || _ || _d | _|j| _d| _|| _d | _|| _|| _dd |	 D | _
d S )NFc                 S  s(   i | ]\}}|t |tr|n| qS r4   )rF   r   _to_pb).0kvr4   r4   r5   
<dictcomp>   s    z5_PipelineResultContainer.__init__.<locals>.<dictcomp>)r^   r\   r)   r-   _started
_read_time_explain_stats_explain_options_return_typeitems_additonal_options)r3   rZ   r\   r^   r`   rb   rd   r4   r4   r5   r6      s   
z!_PipelineResultContainer.__init__r=   r   c                 C  s8   | j d ur| j S | jd u rtd| jstdtd)Nz!explain_options not set on query.z3explain_stats not available until query is completezexplain_stats not found)rm   rn   r   rk   r;   r4   r4   r5   explain_stats   s   

z&_PipelineResultContainer.explain_statsr   c                 C  s   d| j j d| j j }| jdurtj| jddnd}i }| jr'| j |d< | jr0|	| j t
||| jjdi || jd}|S )	zE
        shared logic for creating an ExecutePipelineRequest
        z	projects/z/databases/NF)read_operationrb   )databaser^   structured_pipeliner`   r4   )r-   project	_databaser^   r   get_transaction_idrn   	_to_valuerq   updater   r\   rf   rl   )r3   database_nametransaction_idoptionsrequestr4   r4   r5   _build_request   s$   
z'_PipelineResultContainer._build_requestresponser   Iterable[T]c              	   c  s    |j r
t|j | _|jj}|r| js|| _|jD ])}|jr%| j|jnd}| 	| j|j
|||jr6|jjnd|jr>|jjndV  qdS )z@Shared logic for processing an individual response from a streamN)rr   r   rm   _pbr)   resultsnamer-   documentro   fieldsr+   r,   )r3   r   r)   docr'   r4   r4   r5   _process_response   s"   

z*_PipelineResultContainer._process_responseN)rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   re   )r=   r   )r=   r   )r   r   r=   r   )	r9   rS   rT   rU   r6   rV   rr   r   r   r4   r4   r4   r5   rY      s    

rY   c                   @  s   e Zd ZdZd	ddZdS )
PipelineSnapshotzj
    A list type that holds the result of a pipeline.execute() operation, along with related metadata
    results_listList[T]source_PipelineResultContainer[T]c                 C  s(   | j |j   t| | d| _d S )NT)__dict__rz   copylistr6   rk   )r3   r   r   r4   r4   r5   r6     s   
zPipelineSnapshot.__init__N)r   r   r   r   )r9   rS   rT   rU   r6   r4   r4   r4   r5   r         r   c                   @     e Zd ZdZdddZdS )PipelineStreamzr
    An iterable stream representing the result of a pipeline.stream() operation, along with related metadata
    r=   Iterator[T]c                 c  sT    | j rt| jj dd| _ |  }| jj|}|D ]
}| |E d H  qd S Nz can only be iterated onceT	rk   RuntimeError	__class__r9   r   r-   _firestore_apiexecute_pipeliner   )r3   r~   streamr   r4   r4   r5   __iter__  s   zPipelineStream.__iter__N)r=   r   )r9   rS   rT   rU   r   r4   r4   r4   r5   r     r   r   c                   @  r   )AsyncPipelineStreamzy
    An iterable stream representing the result of an async pipeline.stream() operation, along with related metadata
    r=   AsyncIterator[T]c                 C sj   | j rt| jj dd| _ |  }| jj|I d H }|2 z3 d H W }| |D ]}|V  q+q 6 d S r   r   )r3   r~   r   r   resultr4   r4   r5   	__aiter__&  s   zAsyncPipelineStream.__aiter__N)r=   r   )r9   rS   rT   rU   r   r4   r4   r4   r5   r   !  r   r   )=rU   
__future__r   typingr   r   r   r   r   r   r	   r
   r   r   r   google.cloud.firestore_v1r   $google.cloud.firestore_v1.field_pathr   r   'google.cloud.firestore_v1.query_profiler   r   )google.cloud.firestore_v1.types.firestorer   (google.cloud.firestore_v1.types.documentr   datetime&google.cloud.firestore_v1.async_clientr    google.cloud.firestore_v1.clientr   %google.cloud.firestore_v1.base_clientr   +google.cloud.firestore_v1.async_transactionr   %google.cloud.firestore_v1.transactionr   'google.cloud.firestore_v1.base_documentr   google.protobuf.timestamp_pb2r   r   
ValueProto google.cloud.firestore_v1.vectorr   (google.cloud.firestore_v1.async_pipeliner   'google.cloud.firestore_v1.base_pipeliner   "google.cloud.firestore_v1.pipeliner    .google.cloud.firestore_v1.pipeline_expressionsr!   r"   r#   rW   rY   r   r   r   r4   r4   r4   r5   <module>   sB   4qU