U
    %FZh                  
   @  s   U d Z ddlmZ ddlmZmZ ddlmZ ddlmZ zVddl	m
Z
 ddlmZ e  Ze
j D ]$\ZZedsheekrhee e< qhW n, ek
r Z zed	eW 5 d
Z[X Y nX dZded< dddddddZG dd dZd
S )zCloud Firestore Async module.

This module contains utilities for asynchronusly accessing the Google Cloud Firestore databases
associated with Firebase apps. This requires the ``google-cloud-firestore`` Python module.
    )annotations)OptionalDict)App)_utils)	firestore)DEFAULT_DATABASE_zrFailed to import the Cloud Firestore library for Python. Make sure to install the "google-cloud-firestore" module.NZ_firestore_asyncstr_FIRESTORE_ASYNC_ATTRIBUTEzOptional[App]Optional[str]firestore.AsyncClient)appdatabase_idreturnc                 C  s:   |dk	r"t |ts"td| dt| tt}||S )aP  Returns an async client that can be used to interact with Google Cloud Firestore.

    Args:
        app: An App instance (optional).
        database_id: The database ID of the Google Cloud Firestore database to be used.
            Defaults to the default Firestore database ID if not specified or an empty string
            (optional).

    Returns:
        google.cloud.firestore.Firestore_Async: A `Firestore Async Client`_.

    Raises:
        ValueError: If the specified database ID is not a valid string, or if a project ID is not
            specified either via options, credentials or environment variables, or if the specified
            project ID is not a valid string.

    .. _Firestore Async Client: https://cloud.google.com/python/docs/reference/firestore/latest/        google.cloud.firestore_v1.async_client.AsyncClient
    Nzdatabase_id "z" must be a string or None.)
isinstancer
   
ValueErrorr   Zget_app_servicer   _FirestoreAsyncService
get_client)r   r   Z
fs_service r   e/home/aprabhat/apps/x.techxrdev.in/venv/lib/python3.8/site-packages/firebase_admin/firestore_async.pyclient)   s    r   c                   @  s0   e Zd ZdZdddddZddd	d
dZdS )r   z?Service that maintains a collection of firestore async clients.r   None)r   r   c                 C  s   || _ i | _d S )N)_app_clients)selfr   r   r   r   __init__G   s    z_FirestoreAsyncService.__init__r   r   )r   r   c                 C  sV   |pt }|| jkrL| jj }| jj}|s2tdtj|||d}|| j|< | j| S )zKCreates an async client based on the database_id. These clients are cached.zProject ID is required to access Firestore. Either set the projectId option, or use service account credentials. Alternatively, set the GOOGLE_CLOUD_PROJECT environment variable.)credentialsprojectZdatabase)	r   r   r   Z
credentialget_credentialZ
project_idr   r   ZAsyncClient)r   r   r   r   Z	fs_clientr   r   r   r   K   s    
  
z!_FirestoreAsyncService.get_clientN)__name__
__module____qualname____doc__r   r   r   r   r   r   r   D   s   r   )NN)r#   
__future__r   typingr   r   Zfirebase_adminr   r   Zgoogle.cloudr   Z%google.cloud.firestore_v1.base_clientr   globalskeysexisting__dict__itemskeyvalue
startswithImportErrorerrorr   __annotations__r   r   r   r   r   r   <module>   s$   
