
    ѮhE                    b   U d Z ddlmZ ddlmZmZmZmZmZm	Z	m
Z
 ddlmZ ddlmZ er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Z	 dZded<   dZded<   ej?                  d      Z ded<   ej?                  d      Z!ded<   dZ"ded<   dZ#ded<   dZ$ded<    G d de%      Z& G d de%      Z'y) zEHelpers for applying Google Cloud Firestore changes in a transaction.    )annotations)TYPE_CHECKINGAnyAsyncGenerator	Coroutine	GeneratorOptionalUnion)retry)types)AsyncStreamGenerator)DocumentSnapshot)ExplainOptions)StreamGenerator)write   z@The transaction has already begun. Current transaction ID: {!r}.str_CANT_BEGINz:The transaction has no transaction ID, so it cannot be {}._MISSING_ID_TEMPLATEzrolled back_CANT_ROLLBACK	committed_CANT_COMMITz8Cannot perform write operation in read-only transaction._WRITE_READ_ONLYz.Failed to commit transaction in {:d} attempts._EXCEED_ATTEMPTS_TEMPLATEz,Only read-write transactions can be retried._CANT_RETRY_READ_ONLYc                      e Zd ZdZedfddZddZ	 	 	 	 ddZed        Z	ed        Z
ddZdd
Zd ZddZ	 	 d	 	 	 	 	 	 	 ddZ	 	 dd	d	 	 	 	 	 	 	 ddZy	)BaseTransactiona  Accumulate read-and-write operations to be sent in a transaction.

    Args:
        max_attempts (Optional[int]): The maximum number of attempts for
            the transaction (i.e. allowing retries). Defaults to
            :attr:`~google.cloud.firestore_v1.transaction.MAX_ATTEMPTS`.
        read_only (Optional[bool]): Flag indicating if the transaction
            should be read-only or should allow writes. Defaults to
            :data:`False`.
    Fc                .    || _         || _        d | _        y N)_max_attempts
_read_only_id)selfmax_attempts	read_onlys      |/home/www/academy-backend.kofcorporation.com/venv/lib/python3.12/site-packages/google/cloud/firestore_v1/base_transaction.py__init__zBaseTransaction.__init__@   s    )#    c                    t         r   NotImplementedError)r#   	write_pbss     r&   _add_write_pbszBaseTransaction._add_write_pbsE       !!r(   c                "   |O| j                   rt        t              t        j                  t        j                  j                  |            S | j                   r2t        j                  t        j                  j                               S y)a  Convert the current object to protobuf.

        The ``retry_id`` value is used when retrying a transaction that
        failed (e.g. due to contention). It is intended to be the "first"
        transaction that failed (i.e. if multiple retries are needed).

        Args:
            retry_id (Union[bytes, NoneType]): Transaction ID of a transaction
                to be retried.

        Returns:
            Optional[google.cloud.firestore_v1.types.TransactionOptions]:
            The protobuf ``TransactionOptions`` if ``read_only==True`` or if
            there is a transaction ID to be retried, else :data:`None`.

        Raises:
            ValueError: If ``retry_id`` is not :data:`None` but the
                transaction is read-only.
        N)retry_transaction)
read_write)r%   )r!   
ValueErrorr   r   TransactionOptions	ReadWriteReadOnlyr#   retry_ids     r&   _options_protobufz!BaseTransaction._options_protobufH   s    ,  !677++ 33==&. >  
 __++22;;=  r(   c                    | j                   duS )zDetermine if this transaction has already begun.

        Returns:
            bool: Indicates if the transaction has started.
        Nr"   r#   s    r&   in_progresszBaseTransaction.in_progressn   s     xxt##r(   c                    | j                   S )zGet the current transaction ID.

        Returns:
            Optional[bytes]: The transaction ID (or :data:`None` if the
            current transaction is not in progress).
        r:   r;   s    r&   idzBaseTransaction.idw   s     xxr(   c                     g | _         d| _        y)zClean up the instance after :meth:`_rollback`` or :meth:`_commit``.

        This intended to occur on success or failure of the associated RPCs.
        N)
_write_pbsr"   r;   s    r&   	_clean_upzBaseTransaction._clean_up   s    
 13r(   Nc                    t         r   r*   r6   s     r&   _beginzBaseTransaction._begin   r.   r(   c                    t         r   r*   r;   s    r&   	_rollbackzBaseTransaction._rollback   r.   r(   c                    t         r   r*   r;   s    r&   _commitzBaseTransaction._commit   r.   r(   c                    t         r   r*   )r#   
referencesr   timeouts       r&   get_allzBaseTransaction.get_all   s
     "!r(   )explain_optionsc                   t         r   r*   )r#   ref_or_queryr   rJ   rL   s        r&   getzBaseTransaction.get   s
     "!r(   returnNone)r,   zlist[write_pb.Write])r7   zUnion[bytes, None]rQ   z)Optional[types.common.TransactionOptions]r   )rQ   z&Union[list, Coroutine[Any, Any, list]])NN)rI   listr   2retries.Retry | retries.AsyncRetry | object | NonerJ   float | NonerQ   zcGenerator[DocumentSnapshot, Any, None] | Coroutine[Any, Any, AsyncGenerator[DocumentSnapshot, Any]])r   rT   rJ   rU   rL   zOptional[ExplainOptions]rQ   zStreamGenerator[DocumentSnapshot] | Generator[DocumentSnapshot, Any, None] | Coroutine[Any, Any, AsyncGenerator[DocumentSnapshot, Any]] | Coroutine[Any, Any, AsyncStreamGenerator[DocumentSnapshot]])__name__
__module____qualname____doc__MAX_ATTEMPTSr'   r-   r8   propertyr<   r>   rA   rC   rE   rG   rK   rO    r(   r&   r   r   4   s    	 %1E 
"$*$	2$L $ $  """ EI $		"	" B	" 		"	E	" EI $	" 59" B" 	" 2"	F"r(   r   c                  ,    e Zd ZdZddZddZd Zd Zy)_BaseTransactionalaY  Provide a callable object to use as a transactional decorater.

    This is surfaced via
    :func:`~google.cloud.firestore_v1.transaction.transactional`.

    Args:
        to_wrap (Callable[[:class:`~google.cloud.firestore_v1.transaction.Transaction`, ...], Any]):
            A callable that should be run (and retried) in a transaction.
    c                0    || _         d | _        	 d | _        y r   )to_wrap
current_idr7   )r#   r`   s     r&   r'   z_BaseTransactional.__init__   s    :Ir(   c                     d| _         d| _        y)zUnset the transaction IDs.N)ra   r7   r;   s    r&   _resetz_BaseTransactional._reset   s    r(   c                    t         r   r*   r#   transactionargskwargss       r&   _pre_commitz_BaseTransactional._pre_commit   r.   r(   c                    t         r   r*   re   s       r&   __call__z_BaseTransactional.__call__   r.   r(   NrP   )rV   rW   rX   rY   r'   rc   ri   rk   r\   r(   r&   r^   r^      s    J
""r(   r^   N)(rY   
__future__r   typingr   r   r   r   r   r	   r
   google.api_corer   retriesgoogle.cloud.firestore_v1r   0google.cloud.firestore_v1.async_stream_generatorr   "google.cloud.firestore_v1.documentr   'google.cloud.firestore_v1.query_profiler   *google.cloud.firestore_v1.stream_generatorr   google.cloud.firestore_v1.typesr   write_pbrZ   r   __annotations__r   formatr   r   r   r   r   objectr   r^   r\   r(   r&   <module>rz      s    L "   - + UCFJA  AUS UX c X*11-@ @(//<c <R # R!Q 3 QK s Kv"f v"r" "r(   