
    (phK                        S r SSKJr  SSKrSSKrSSKJrJrJrJ	r	  SSK
Jr  SSK
Jr  SSKJr  SSKJr  SS	KJr  SS
KJrJrJr  SSKJr  SSKJr  \R8                  " \5      r " S S\5      rg)zFClasses for representing documents for the Google Cloud Firestore API.    )annotationsN)AnyCallable	GeneratorIterable)gapic_v1)retry)_datetime_to_pb_timestamp)	Timestamp)_helpers)BaseDocumentReferenceDocumentSnapshot_first_write_result)write)Watchc                    ^  \ rS rSrSrSU 4S jjr\R                  R                  S4       SS jjr	S\R                  R                  S4         SS jjr
S\R                  R                  S4         SS jjrS\R                  R                  S4       SS	 jjrSS\R                  R                  S4       SS
 jjrS\R                  R                  S4       SS jjrSS jrSrU =r$ )DocumentReference&   a  A reference to a document in a Firestore database.

The document may already exist or can be created by this class.

Args:
    path (Tuple[str, ...]): The components in the document path.
        This is a series of strings representing each collection and
        sub-collection ID, as well as the document IDs for any documents
        that contain a sub-collection (as well as the base document).
    kwargs (dict): The keyword arguments for the constructor. The only
        supported keyword is ``client`` and it must be a
        :class:`~google.cloud.firestore_v1.client.Client`. It represents
        the client that created this document reference.

Raises:
    ValueError: if

        * the ``path`` is empty
        * there are an even number of elements
        * a collection ID in ``path`` is not a string
        * a document ID in ``path`` is not a string
    TypeError: If a keyword other than ``client`` is used.
c                .   > [         [        U ]
  " U0 UD6  g )N)superr   __init__)selfpathkwargs	__class__s      U/var/www/html/venv/lib/python3.13/site-packages/google/cloud/firestore_v1/document.pyr   DocumentReference.__init__?   s    /@@    Nc                d    U R                  XU5      u  pEUR                  " S0 UD6n[        U5      $ )ap  Create a document in the Firestore database.

>>> document_data = {"a": 1, "b": {"c": "Two"}}
>>> document.get().to_dict() is None  # does not exist
True
>>> document.create(document_data)
>>> document.get().to_dict() == document_data  # exists
True

Args:
    document_data (dict): Property names and values to use for
        creating a document.
    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:
    :class:`~google.cloud.firestore_v1.types.WriteResult`:
        The write result corresponding to the committed document.
        A write result contains an ``update_time`` field.

Raises:
    :class:`google.cloud.exceptions.Conflict`:
        If the document already exists.
 )_prep_createcommitr   )r   document_datar	   timeoutbatchr   write_resultss          r   createDocumentReference.createB   s5    @ ))-H.v."=11r   Fc                d    U R                  XX45      u  pVUR                  " S0 UD6n[        U5      $ )an  Create / replace / merge a document in the Firestore database.

- To "upsert" a document (create if it doesn't exist, replace completely
  if it does), leave the ``merge`` argument at its default:

  >>> document_data = {"a": 1, "b": {"c": "Two"}}
  >>> document.get().to_dict() is None  # document exists
  False
  >>> document.set(document_data)
  >>> document.get().to_dict() == document_data  # exists
  True

- To "merge" ``document_data`` with an existing document (creating if
  the document does not exist), pass ``merge`` as True``:

  >>> document_data = {"a": 1, "b": {"c": "Two"}}
  >>> document.get().to_dict() == {"d": "Three", "b": {}} # exists
  >>> document.set(document_data, merge=True)
  >>> document.get().to_dict() == {"a": 1, "d": "Three", "b": {"c": "Two"}}
  True

  In this case, existing documents with top-level keys which are
  not present in ``document_data`` (``"d"``) will preserve the values
  of those keys.


- To merge only specific fields of ``document_data`` with existing
  documents (creating if the document does not exist), pass ``merge``
  as a list of field paths:


  >>> document_data = {"a": 1, "b": {"c": "Two"}}
  >>> document.get().to_dict() == {"b": {"c": "One", "d": "Four" }} # exists
  True
  >>> document.set(document_data, merge=["b.c"])
  >>> document.get().to_dict() == {"b": {"c": "Two", "d": "Four" }}
  True

  For more information on field paths, see
  :meth:`~google.cloud.firestore_v1.base_client.BaseClient.field_path`.

Args:
    document_data (dict): Property names and values to use for
        replacing a document.
    merge (Optional[bool] or Optional[List<fieldpath>]):
        If True, apply merging instead of overwriting the state
        of the document.
    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:
    :class:`~google.cloud.firestore_v1.types.WriteResult`:
    The write result corresponding to the committed document. A write
    result contains an ``update_time`` field.
r    )	_prep_setr"   r   )r   r#   merger	   r$   r%   r   r&   s           r   setDocumentReference.setf   s3    @ }UL.v."=11r   c                d    U R                  XX45      u  pVUR                  " S0 UD6n[        U5      $ )a  Update an existing document in the Firestore database.

By default, this method verifies that the document exists on the
server before making updates. A write ``option`` can be specified to
override these preconditions.

Each key in ``field_updates`` can either be a field name or a
**field path** (For more information on field paths, see
:meth:`~google.cloud.firestore_v1.base_client.BaseClient.field_path`.)
To illustrate this, consider a document with

.. code-block:: python

   >>> snapshot = document.get()
   >>> snapshot.to_dict()
   {
       'foo': {
           'bar': 'baz',
       },
       'other': True,
   }

stored on the server. If the field name is used in the update:

.. code-block:: python

   >>> field_updates = {
   ...     'foo': {
   ...         'quux': 800,
   ...     },
   ... }
   >>> document.update(field_updates)

then all of ``foo`` will be overwritten on the server and the new
value will be

.. code-block:: python

   >>> snapshot = document.get()
   >>> snapshot.to_dict()
   {
       'foo': {
           'quux': 800,
       },
       'other': True,
   }

On the other hand, if a ``.``-delimited **field path** is used in the
update:

.. code-block:: python

   >>> field_updates = {
   ...     'foo.quux': 800,
   ... }
   >>> document.update(field_updates)

then only ``foo.quux`` will be updated on the server and the
field ``foo.bar`` will remain intact:

.. code-block:: python

   >>> snapshot = document.get()
   >>> snapshot.to_dict()
   {
       'foo': {
           'bar': 'baz',
           'quux': 800,
       },
       'other': True,
   }

.. warning::

   A **field path** can only be used as a top-level key in
   ``field_updates``.

To delete / remove a field from an existing document, use the
:attr:`~google.cloud.firestore_v1.transforms.DELETE_FIELD` sentinel.
So with the example above, sending

.. code-block:: python

   >>> field_updates = {
   ...     'other': firestore.DELETE_FIELD,
   ... }
   >>> document.update(field_updates)

would update the value on the server to:

.. code-block:: python

   >>> snapshot = document.get()
   >>> snapshot.to_dict()
   {
       'foo': {
           'bar': 'baz',
       },
   }

To set a field to the current time on the server when the
update is received, use the
:attr:`~google.cloud.firestore_v1.transforms.SERVER_TIMESTAMP`
sentinel.
Sending

.. code-block:: python

   >>> field_updates = {
   ...     'foo.now': firestore.SERVER_TIMESTAMP,
   ... }
   >>> document.update(field_updates)

would update the value on the server to:

.. code-block:: python

   >>> snapshot = document.get()
   >>> snapshot.to_dict()
   {
       'foo': {
           'bar': 'baz',
           'now': datetime.datetime(2012, ...),
       },
       'other': True,
   }

Args:
    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.
    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:
    :class:`~google.cloud.firestore_v1.types.WriteResult`:
    The write result corresponding to the updated document. A write
    result contains an ``update_time`` field.

Raises:
    :class:`google.cloud.exceptions.NotFound`:
        If the document does not exist.
r    )_prep_updater"   r   )r   field_updatesoptionr	   r$   r%   r   r&   s           r   updateDocumentReference.update   s5    t ))-P.v."=11r   c                    U R                  XU5      u  pEU R                  R                  R                  " SUU R                  R                  S.UD6nUR
                  $ )aI  Delete the current document in the Firestore database.

Args:
    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.
    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:
    :class:`google.protobuf.timestamp_pb2.Timestamp`:
    The time that the delete request was received by the server.
    If the document did not exist when the delete was sent (i.e.
    nothing was deleted), this method will still succeed and will
    still return the time that the request was received by the server.
requestmetadatar    )_prep_delete_client_firestore_apir"   _rpc_metadatacommit_time)r   r1   r	   r$   r6   r   commit_responses          r   deleteDocumentReference.deleteH  s_    0 ++F7C,,55<< 
\\//
 
 ***r   c           	        SSK Jn  U R                  XX45      u  pgU R                  R                  R
                  " S	UU R                  R                  S.UD6n[        US5      n	U	b  U" U	U R                  U 0U R                  S9$ [        R                  S5        [        U SS[        [        R                  R                  5       5      SSS9$ )
a|  Retrieve a snapshot of the current document.

See :meth:`~google.cloud.firestore_v1.base_client.BaseClient.field_path` for
more information on **field paths**.

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).

Args:
    field_paths (Optional[Iterable[str, ...]]): An iterable of field
        paths (``.``-delimited list of field names) to use as a
        projection of document fields in the returned results. If
        no value is provided, all fields will be returned.
    transaction (Optional[:class:`~google.cloud.firestore_v1.transaction.Transaction`]):
        An existing transaction that this reference
        will be retrieved in.
    retry (google.api_core.retry.Retry): Designation of what errors, if an                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      y,
        should be retried.  Defaults to a system-specified policy.
    timeout (float): The timeout for this request.  Defaults to a
        system-specified value.

Returns:
    :class:`~google.cloud.firestore_v1.base_document.DocumentSnapshot`:
        A snapshot of the current document. If the document does not
        exist at the time of the snapshot is taken, the snapshot's
        :attr:`reference`, :attr:`data`, :attr:`update_time`, and
        :attr:`create_time` attributes will all be ``None`` and
        its :attr:`exists` attribute will be ``False``.
r   )_parse_batch_getr5   N)get_doc_responsereference_mapclientzN`batch_get_documents` unexpectedly returned empty stream. Expected one object.F)exists	read_timecreate_timeupdate_timer    )%google.cloud.firestore_v1.base_clientrA   _prep_batch_getr9   r:   batch_get_documentsr;   next_document_pathloggerwarningr   r
   datetimenow)
r   field_pathstransactionr	   r$   rA   r6   r   response_iterrB   s
             r   getDocumentReference.getj  s    J 	K..{X33GG 
\\//
 
  t4'#!1#22D9||  	+	

  /0A0A0E0E0GH
 	
r   c              #     #    U R                  XU5      u  pEU R                  R                  R                  " SUU R                  R                  S.UD6nU H  nU R                  U5      v   M     g7f)a  List subcollections of the current document.

Args:
    page_size (Optional[int]]): The maximum number of collections
        in each page of results from this request. Non-positive values
        are ignored. Defaults to a sensible value set by the API.
    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:
    Sequence[:class:`~google.cloud.firestore_v1.collection.CollectionReference`]:
        iterator of subcollections of the current document. If the
        document does not exist at the time of `snapshot`, the
        iterator will be empty
r5   Nr    )_prep_collectionsr9   r:   list_collection_idsr;   
collection)r   	page_sizer	   r$   r6   r   iteratorcollection_ids           r   collectionsDocumentReference.collections  so     . 007K<<..BB 
\\//
 
 &M//-00 &s   A/A1c                8    [         R                  " X[        5      $ )a4  Watch this document.

This starts a watch on this document using a background thread. The
provided callback is run on the snapshot.

Args:
    callback(Callable[[:class:`~google.cloud.firestore_v1.base_document.DocumentSnapshot`], NoneType]):
        a callback to run when a change occurs

Example:

.. code-block:: python

    from google.cloud import firestore_v1

    db = firestore_v1.Client()
    collection_ref = db.collection(u'users')

    def on_snapshot(document_snapshot, changes, read_time):
        doc = document_snapshot
        print(u'{} => {}'.format(doc.id, doc.to_dict()))

    doc_ref = db.collection(u'users').document(
        u'alovelace' + unique_resource_id())

    # Watch this document
    doc_watch = doc_ref.on_snapshot(on_snapshot)

    # Terminate this watch
    doc_watch.unsubscribe()
)r   for_documentr   )r   callbacks     r   on_snapshotDocumentReference.on_snapshot  s    @ !!$2BCCr   r    )returnNone)r#   dictr	   retries.Retry | object | Noner$   float | Nonere   write.WriteResult)
r#   rg   r+   boolr	   rh   r$   ri   re   rj   )
r0   rg   r1   _helpers.WriteOption | Noner	   rh   r$   ri   re   rj   )r1   rl   r	   rh   r$   ri   re   r   )rR   zIterable[str] | Noner	   rh   r$   ri   re   r   )r[   z
int | Noner	   rh   r$   ri   re   zGenerator[Any, Any, None])rb   r   re   r   )__name__
__module____qualname____firstlineno____doc__r   r   methodDEFAULTr'   r,   r2   r>   rU   r^   rc   __static_attributes____classcell__)r   s   @r   r   r   &   s   0A 08/F/F $	"2"2 -"2 	"2
 
"2N /7/F/F $B2B2 B2 -	B2
 B2 
B2N /3/7/F/F $\2\2 ,\2 -	\2
 \2 
\2@ /3/7/F/F $	 ++ + - + 	 +
 
 +H -1/7/F/F $D
)D
 -	D

 D
 
D
P !%/7/F/F $	 1 1 - 1 	 1
 
# 1D D  Dr   r   ) rq   
__future__r   rP   loggingtypingr   r   r   r   google.api_corer   r	   retriesgoogle.cloud._helpersr
   google.protobuf.timestamp_pb2r   google.cloud.firestore_v1r   'google.cloud.firestore_v1.base_documentr   r   r   google.cloud.firestore_v1.typesr   google.cloud.firestore_v1.watchr   	getLoggerrm   rN   r   r    r   r   <module>r      s\    M "   5 5 $ , ; 3 . 
 2 1			8	$LD- LDr   