o
    }l~i#                     @  s   d 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rPd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 G dd de	Zd	S )z
.. warning::
    **Preview API**: Firestore Pipelines is currently in preview and is
    subject to potential breaking changes in future releases
    )annotations)TYPE_CHECKING)pipeline_stages)_BasePipeline)AsyncPipelineStream)PipelineSnapshot)PipelineResultN)AsyncClient)AsyncTransaction)Constant)Value)PipelineExplainOptionsc                      sN   e Zd ZdZd fddZdddi d	dddZdddi ddddZ  ZS )AsyncPipelinea	  
    Pipelines allow for complex data transformations and queries involving
    multiple stages like filtering, projection, aggregation, and vector search.

    This class extends `_BasePipeline` and provides methods to execute the
    defined pipeline stages using an asynchronous `AsyncClient`.

    Usage Example:
        >>> from google.cloud.firestore_v1.pipeline_expressions import Field
        >>>
        >>> async def run_pipeline():
        ...     client = AsyncClient(...)
        ...     pipeline = client.pipeline()
        ...                      .collection("books")
        ...                      .where(Field.of("published").gt(1980))
        ...                      .select("title", "author")
        ...     async for result in pipeline.stream():
        ...         print(result)

    Use `client.pipeline()` to create instances of this class.

    .. warning::
        **Preview API**: Firestore Pipelines is currently in preview and is
        subject to potential breaking changes in future releases
    clientr	   stagesstages.Stagec                   s   t  j|g|R   dS )z
        Initializes an asynchronous Pipeline.

        Args:
            client: The asynchronous `AsyncClient` instance to use for execution.
            *stages: Initial stages for the pipeline.
        N)super__init__)selfr   r   	__class__ o/var/www/newdalilibackend/backend/venv/lib/python3.10/site-packages/google/cloud/firestore_v1/async_pipeline.pyr   @   s   zAsyncPipeline.__init__N)transaction	read_timeexplain_optionsadditional_optionsr   'AsyncTransaction' | Noner   datetime.datetime | Noner   PipelineExplainOptions | Noner   dict[str, Value | Constant]return PipelineSnapshot[PipelineResult]c                  sF   dd t   D }tt| fi |}dd |2 I dH }t||S )a(  
        Executes this pipeline and returns results as a list

        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).
            read_time (Optional[datetime.datetime]): If set, reads documents as they were at the given
                time. This must be a microsecond precision 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. For the most accurate results, use UTC timezone.
            explain_options (Optional[:class:`~google.cloud.firestore_v1.query_profile.PipelineExplainOptions`]):
                Options to enable query profiling for this query. When set,
                explain_metrics will be available on the returned list.
            additional_options (Optional[dict[str, Value | Constant]]): Additional options to pass to the query.
                These options will take precedence over method argument if there is a conflict (e.g. explain_options)
        c                 S     i | ]\}}|d kr||qS r   r   .0kvr   r   r   
<dictcomp>e       z)AsyncPipeline.execute.<locals>.<dictcomp>c                   s   g | z3 d H W }|q6 S )Nr   )r&   resultr   r   r   
<listcomp>g   s    z)AsyncPipeline.execute.<locals>.<listcomp>N)localsitemsr   r   r   )r   r   r   r   r   kwargsstreamresultsr   r   r   executeJ   s
   
zAsyncPipeline.execute)r   r   r   r   #AsyncPipelineStream[PipelineResult]c                C  s&   dd t   D }tt| fi |S )aF  
        Process this pipeline as a stream, providing results through an AsyncIterable

        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).
            read_time (Optional[datetime.datetime]): If set, reads documents as they were at the given
                time. This must be a microsecond precision 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. For the most accurate results, use UTC timezone.
            explain_options (Optional[:class:`~google.cloud.firestore_v1.query_profile.PipelineExplainOptions`]):
                Options to enable query profiling for this query. When set,
                explain_metrics will be available on the returned generator.
            additional_options (Optional[dict[str, Value | Constant]]): Additional options to pass to the query.
                These options will take precedence over method argument if there is a conflict (e.g. explain_options)
        c                 S  r#   r$   r   r%   r   r   r   r)      r*   z(AsyncPipeline.stream.<locals>.<dictcomp>)r-   r.   r   r   )r   r   r   r   r   r/   r   r   r   r0   j   s   zAsyncPipeline.stream)r   r	   r   r   )
r   r   r   r   r   r   r   r    r!   r"   )
r   r   r   r   r   r   r   r    r!   r3   )__name__
__module____qualname____doc__r   r2   r0   __classcell__r   r   r   r   r   %   s    #r   )r7   
__future__r   typingr   google.cloud.firestore_v1r   r   'google.cloud.firestore_v1.base_pipeliner   )google.cloud.firestore_v1.pipeline_resultr   r   r   datetime&google.cloud.firestore_v1.async_clientr	   +google.cloud.firestore_v1.async_transactionr
   .google.cloud.firestore_v1.pipeline_expressionsr   (google.cloud.firestore_v1.types.documentr   'google.cloud.firestore_v1.query_profiler   r   r   r   r   r   <module>   s    