
    5                     n    d 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d	Z	d
 Z
d Z	 ddZ	 ddZy)zGUseful commands for interacting with the Cloud Firestore Databases API.    )absolute_import)division)unicode_literals)	api_utilsc                  >    t        j                         j                  S )zEReturns the service for interacting with the Firestore admin service.)r   	GetClientprojects_databases     1lib/googlecloudsdk/api_lib/firestore/databases.py_GetDatabaseServicer      s    					1	11r   c                     t        j                         }t               j                  |j	                  dj                  | |                  S )zPerforms a Firestore Admin v1 Database Get.

  Args:
    project: the project id to get, a string.
    database: the database id to get, a string.

  Returns:
    a database.
  projects/{}/databases/{})name)r   GetMessagesr   Get$FirestoreProjectsDatabasesGetRequestformat)projectdatabasemessagess      r   GetDatabaser      sK     ""$(			"	"33)00(C 4 
 r   Nc	                    t        j                         }	t        j                  ||	j                  j                        }
t               j                  |	j                  dj                  |       ||	j                  |||||||
                  S )aq  Performs a Firestore Admin v1 Database Creation.

  Args:
    project: the project id to create, a string.
    location: the database location to create, a string.
    database: the database id to create, a string.
    database_type: the database type, an Enum.
    database_edition: the database edition, an Enum.
    delete_protection_state: the value for deleteProtectionState, an Enum.
    pitr_state: the value for PitrState, an Enum.
    cmek_config: the CMEK config used to encrypt the database, an object.
    tags: the tags to attach to the database, a key-value dictionary, or None.

  Returns:
    an Operation.
  projects/{})typedatabaseEdition
locationIddeleteProtectionStatepointInTimeRecoveryEnablement
cmekConfigtags)parent
databaseIdgoogleFirestoreAdminV1Database)	r   r   ParseTagsForTagsValueGoogleFirestoreAdminV1Database	TagsValuer   Create'FirestoreProjectsDatabasesCreateRequestr   )r   locationr   database_typedatabase_editiondelete_protection_state
pitr_statecmek_configr!   r   
tags_values              r   CreateDatabaser1   /   s    6 ""$(..
H33==* 
		%	%66%%g.)1)P)P .!$;,6$ *Q * 7 
 r   c                     t        j                         }t               j                  |j	                  dj                  | |      |            S )a  Performs a Firestore Admin v1 Database Deletion.

  Args:
    project: the project of the database to delete, a string.
    database: the database id to delete, a string.
    etag: the current etag of the Database, a string.

  Returns:
    an Operation.
  r   )r   etag)r   r   r   Delete'FirestoreProjectsDatabasesDeleteRequestr   )r   r   r3   r   s       r   DeleteDatabaser6   _   sN     ""$(			%	%66)00(C 7 
 r   c           	          t        j                         }t        t               j	                  |j                  dj                  |       |rdnd            j                        S )zLists all Firestore databases under the project.

  Args:
    project: the project ID to list databases, a string.
    show_deleted: if true, also returns deleted resources, a boolean.

  Returns:
    a List of Databases.
  r   TN)r"   showDeleted)r   r   listr   List%FirestoreProjectsDatabasesListRequestr   	databases)r   show_deletedr   s      r   ListDatabasesr>   s   s^     ""$(	t

8
8"))'2".$D 9  y	
 	r   c                    t        j                         }t        j                  ||j                  j                        }|j                  ||||      }t               j                  |j                  dj                  |       |            S )a  Restores a Firestore database from a backup.

  Args:
    project: the project ID to list databases, a string.
    source_backup: the backup to restore from, a string.
    destination_database: the database to restore to, a string.
    encryption_config: the encryption config to use for the restored database,
      an optional object.
    tags: the tags to attach to the database, a key-value dictionary.

  Returns:
    an Operation.
  )backupr#   encryptionConfigr!   r   )r"   ,googleFirestoreAdminV1RestoreDatabaseRequest)	r   r   r%   ,GoogleFirestoreAdminV1RestoreDatabaseRequestr'   r   Restore(FirestoreProjectsDatabasesRestoreRequestr   )r   source_backupdestination_databaseencryption_configr!   r   r0   restore_requests           r   RestoreDatabaserJ      s    ( ""$(..
HAAKK* II%(	 J / 
		&	&77%%g.7F 8 
 r   c                 <   t        j                         }t        j                  ||j                  j                        }|j                  |j                  ||      |||      }t               j                  |j                  dj                  |       |            S )a  Clones one Firestore database from another.

  Args:
    project: the project ID containing the source database, a string.
    source_database: the resource name of the database to clone, a string.
    snapshot_time: the timestamp at which to clone, a DateTime.
    destination_database: the database to clone to, a string.
    encryption_config: the encryption config to use for the cloned database, an
      optional object.
    tags: the tags to attach to the database, a key-value dictionary, or None.

  Returns:
    an Operation.
  )r   snapshotTime)pitrSnapshotr#   rA   r!   r   )r"   *googleFirestoreAdminV1CloneDatabaseRequest)
r   r   r%   *GoogleFirestoreAdminV1CloneDatabaseRequestr'   "GoogleFirestoreAdminV1PitrSnapshotr   Clone&FirestoreProjectsDatabasesCloneRequestr   )	r   source_databasesnapshot_timerG   rH   r!   r   r0   clone_requests	            r   CloneDatabaserV      s    , ""$(..
H??II* EE>>"$ ?  &( F - 
		$	$55%%g.5B 6 
 r   )N)__doc__
__future__r   r   r    googlecloudsdk.api_lib.firestorer   r   r   r1   r6   r>   rJ   rV   r
   r   r   <module>rZ      sK    N &  ' 62
6 
-`(8 
$Z 
)r   