o
    ,=j`  ã                   @  sH   d 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=Helpers for batch requests to the Google Cloud Firestore API.é    )Úannotations)Úgapic_v1)Úretry)ÚBaseWriteBatchc                      sF   e Zd ZdZd‡ fdd„Zejjdf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.
    ÚreturnÚNonec                   s   t t| ƒj|d� d S )N)Úclient)Úsuperr   Ú__init__)Úselfr	   ©Ú	__class__© úiC:\Users\psant\Downloads\Anu Raj Backend\school\venv\Lib\site-packages\google/cloud/firestore_v1/batch.pyr   '   s   zWriteBatch.__init__Nr   úretries.Retry | object | NoneÚtimeoutúfloat | NoneÚlistc                 C  sP   |   ||¡\}}| jjjd|| 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.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ÚmetadataNr   )	Z_prep_commitZ_clientZ_firestore_apiÚcommitZ_rpc_metadataZ
_write_pbsr   Z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__K   s   zWriteBatch.__enter__c                 C  s   |d u r
|   ¡  d S d S r   )r   )r   Úexc_typeÚ	exc_valueÚ	tracebackr   r   r   Ú__exit__N   s   ÿzWriteBatch.__exit__)r   r   )r   r   r   r   r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   ÚmethodÚDEFAULTr   r   r   Ú__classcell__r   r   r   r   r      s    ý!r   N)
r#   Ú
__future__r   Zgoogle.api_corer   r   ÚretriesZ$google.cloud.firestore_v1.base_batchr   r   r   r   r   r   Ú<module>   s   