o
    0=j  ã                
   @  sÔ   d Z ddlmZ ddlmZmZ ddlmZ ddlmZ z+ddl	m
Z
 ddlmZ eƒ  ¡ Ze
j ¡ D ]\ZZe d¡sEeevrEeeƒ e< q3W n eyX Z zed	ƒe‚d
Z[ww dZdddd„ZG dd„ dƒZd
S )zÆCloud Firestore module.

This module contains utilities for 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ÚappúOptional[App]Údatabase_idúOptional[str]Úreturnúfirestore.Clientc                 C  s:   |durt |tƒstd|› d�ƒ‚t | tt¡}| |¡S )a,  Returns a 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: A `Firestore 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 Client: https://cloud.google.com/python/docs/reference/firestore/latest/        google.cloud.firestore_v1.client.Client
    Nzdatabase_id "z" must be a string or None.)Ú
isinstanceÚstrÚ
ValueErrorr   Zget_app_serviceÚ_FIRESTORE_ATTRIBUTEÚ_FirestoreServiceÚ
get_client)r
   r   Z
fs_service© r   úbC:\Users\psant\Downloads\Anu Raj Backend\school\venv\Lib\site-packages\firebase_admin/firestore.pyÚclient)   s   
r   c                   @  s$   e Zd ZdZddd„Zddd„ZdS )r   z9Service that maintains a collection of firestore clients.r
   r   r   ÚNonec                 C  s   || _ i | _d S )N)Ú_appÚ_clients)Úselfr
   r   r   r   Ú__init__G   s   
z_FirestoreService.__init__r   r   r   c                 C  sV   |pt }|| jvr&| jj ¡ }| jj}|stdƒ‚tj|||d�}|| j|< | j| S )zDCreates a client based on the database_id. These clients are cached.z²Project 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databaseN)	r   r   r   Z
credentialÚget_credentialZ
project_idr   r   ZClient)r   r   r   r   Z	fs_clientr   r   r   r   K   s   
ÿÿ

z_FirestoreService.get_clientN)r
   r   r   r   )r   r   r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   D   s    
r   )NN)r
   r   r   r   r   r   )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   r   r   r   r   r   r   Ú<module>   s.   

€þÿ€ÿ