a
    !f                     @   s<   d 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=Helpers for batch requests to the Google Cloud Firestore API.    )gapic_v1)retry)BaseWriteBatchc                       sT   e Zd ZdZdd fddZejjdfej	e
edddZd	d
 Zdd Z  ZS )
WriteBatcha
  Accumulate write operations to be sent in a batch. Use this over
    `BulkWriteBatch` for lower volumes or when the order of operations
    within a given batch is important.

    This has the same set of methods for write operations that
    :class:`~google.cloud.firestore_v1.document.DocumentReference` does,
    e.g. :meth:`~google.cloud.firestore_v1.document.DocumentReference.create`.

    Args:
        client (:class:`~google.cloud.firestore_v1.client.Client`):
            The client that created this batch.
    N)returnc                    s   t t| j|d d S )N)client)superr   __init__)selfr   	__class__ `/var/www/html/python-backend/venv/lib/python3.9/site-packages/google/cloud/firestore_v1/batch.pyr	   %   s    zWriteBatch.__init__)r   timeoutr   c                 C   sP   |  ||\}}| jjjf || jjd|}g | _t|j | _}|j| _|S )a  Commit the changes accumulated in this batch.

        Args:
            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[:class:`google.cloud.proto.firestore.v1.write.WriteResult`, ...]:
            The write results corresponding to the changes committed, returned
            in the same order as the changes were applied to this batch. A
            write result contains an ``update_time`` field.
        )requestmetadata)	Z_prep_commitZ_clientZ_firestore_apicommitZ_rpc_metadataZ
_write_pbslistZwrite_resultsZcommit_time)r
   r   r   r   kwargsZcommit_responseresultsr   r   r   r   (   s    
zWriteBatch.commitc                 C   s   | S Nr   )r
   r   r   r   	__enter__G   s    zWriteBatch.__enter__c                 C   s   |d u r|    d S r   )r   )r
   exc_type	exc_value	tracebackr   r   r   __exit__J   s    zWriteBatch.__exit__)__name__
__module____qualname____doc__r	   r   methodDEFAULTretriesRetryfloatr   r   r   r   __classcell__r   r   r   r   r      s   r   N)r   Zgoogle.api_corer   r   r"   Z$google.cloud.firestore_v1.base_batchr   r   r   r   r   r   <module>   s   