
    Ѯh>                        d Z ddlmZ ddlZddlmZ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j"                        Z G d de      Zy)z=Helpers for batch requests to the Google Cloud Firestore API.    )annotationsN)DictUnion)retry)_helpers)BaseDocumentReference)writec                      e Zd ZdZddZd ZddZddZej                  d        Z
ddZ	 d	 	 	 	 	 	 	 ddZ	 d	 	 	 	 	 	 	 dd
Z	 d	 	 	 	 	 ddZy	)	BaseBatcha  Accumulate write operations to be sent in a batch.

    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.
    c                J    || _         g | _        i | _        d | _        d | _        y N)_client
_write_pbs_document_referenceswrite_resultscommit_time)selfclients     v/home/www/academy-backend.kofcorporation.com/venv/lib/python3.12/site-packages/google/cloud/firestore_v1/base_batch.py__init__zBaseBatch.__init__(   s(    02FH!@D    c                ,    t        | j                        S r   )lenr   r   s    r   __len__zBaseBatch.__len__/   s    4,,--r   c                2    |j                   | j                  v S r   )_document_pathr   )r   	references     r   __contains__zBaseBatch.__contains__2   s    ''4+D+DDDr   c                :    | j                   j                  |       y)a  Add `Write`` protobufs to this transaction.

        This method intended to be over-ridden by subclasses.

        Args:
            write_pbs (List[google.cloud.firestore_v1.                write_pb2.Write]): A list of write protobufs to be added.
        N)r   extend)r   	write_pbss     r   _add_write_pbszBaseBatch._add_write_pbs5   s     	y)r   c                    t               )zySends all accumulated write operations to the server. The details of this
        write depend on the implementing class.)NotImplementedErrorr   s    r   commitzBaseBatch.commit@   s     "##r   c                    t        j                  |j                  |      }|| j                  |j                  <   | j	                  |       y)a  Add a "change" to this batch to create a document.

        If the document given by ``reference`` already exists, then this
        batch will fail when :meth:`commit`-ed.

        Args:
            reference (:class:`~google.cloud.firestore_v1.document.DocumentReference`):
                A document reference to be created in this batch.
            document_data (dict): Property names and values to use for
                creating a document.
        N)r   pbs_for_creater   r   r#   )r   r   document_datar"   s       r   createzBaseBatch.createF   s@     ++I,D,DmT	>G!!)":":;I&r   c                    |dur"t        j                  |j                  ||      }n t        j                  |j                  |      }|| j                  |j                  <   | j                  |       y)a  Add a "change" to replace a document.

        See
        :meth:`google.cloud.firestore_v1.document.DocumentReference.set` for
        more information on how ``option`` determines how the change is
        applied.

        Args:
            reference (:class:`~google.cloud.firestore_v1.document.DocumentReference`):
                A document reference that will have values set in this batch.
            document_data (dict):
                Property names and values to use for replacing a document.
            merge (Optional[bool] or Optional[List<apispec>]):
                If True, apply merging instead of overwriting the state
                of the document.
        FN)r   pbs_for_set_with_merger   pbs_for_set_no_merger   r#   )r   r   r)   merger"   s        r   setzBaseBatch.setV   sm    ,  77((-I !55((-I ?H!!)":":;I&r   Nc                    |j                   j                  dk(  rt        d      t        j                  |j
                  ||      }|| j                  |j
                  <   | j                  |       y)a  Add a "change" to update a document.

        See
        :meth:`google.cloud.firestore_v1.document.DocumentReference.update`
        for more information on ``field_updates`` and ``option``.

        Args:
            reference (:class:`~google.cloud.firestore_v1.document.DocumentReference`):
                A document reference that will be updated in this batch.
            field_updates (dict):
                Field names or paths to update and values to update with.
            option (Optional[:class:`~google.cloud.firestore_v1.client.WriteOption`]):
                A write option to make assertions / preconditions on the server
                state of the document before applying changes.
        ExistsOptionz5you must not pass an explicit write option to update.N)	__class____name__
ValueErrorr   pbs_for_updater   r   r#   )r   r   field_updatesoptionr"   s        r   updatezBaseBatch.updatex   sh    * $$6WXX++$$mV
	 ?H!!)":":;I&r   c                    t        j                  |j                  |      }|| j                  |j                  <   | j	                  |g       y)ay  Add a "change" to delete a document.

        See
        :meth:`google.cloud.firestore_v1.document.DocumentReference.delete`
        for more information on how ``option`` determines how the change is
        applied.

        Args:
            reference (:class:`~google.cloud.firestore_v1.document.DocumentReference`):
                A document reference that will be deleted in this batch.
            option (Optional[:class:`~google.cloud.firestore_v1.client.WriteOption`]):
                A write option to make assertions / preconditions on the server
                state of the document before applying changes.
        N)r   pb_for_deleter   r   r#   )r   r   r7   write_pbs       r   deletezBaseBatch.delete   sB    & )))*B*BFK>G!!)":":;XJ'r   )returnNone)r   r   )r"   zlist[write_pb.Write]r=   r>   )r   r   r)   dictr=   r>   )F)r   r   r)   r?   r.   zUnion[bool, list]r=   r>   r   )r   r   r6   r?   r7   _helpers.WriteOption | Noner=   r>   )r   r   r7   r@   r=   r>   )r3   
__module____qualname____doc__r   r   r   r#   abcabstractmethodr&   r*   r/   r8   r<    r   r   r   r      s    	 .E	* 	$ $
'( $)	 '( '  ' !	 '
 
 'L /3	'(' ' ,	'
 
'@ /3((( ,( 
	(r   r   )	metaclassc                       e Zd ZdZ	 	 	 	 ddZy)BaseWriteBatchzBase class for a/sync implementations of the `commit` RPC. `commit` is useful
    for lower volumes or when the order of write operations is important.c                ~    | j                   j                  | j                  dd}t        j                  ||      }||fS )z+Shared setup for async/sync :meth:`commit`.N)databasewritestransaction)r   _database_stringr   r   make_retry_timeout_kwargs)r   r   timeoutrequestkwargss        r   _prep_commitzBaseWriteBatch._prep_commit   s@     55oo

 33E7Cr   N)r   z2retries.Retry | retries.AsyncRetry | object | NonerP   zfloat | None)r3   rA   rB   rC   rS   rF   r   r   rI   rI      s    MA r   rI   )rC   
__future__r   rD   typingr   r   google.api_corer   retriesgoogle.cloud.firestore_v1r   'google.cloud.firestore_v1.base_documentr   google.cloud.firestore_v1.typesr	   r;   ABCMetar   rI   rF   r   r   <module>r\      sA    D " 
  - . I =N(#++ N(bY r   