
                             S 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
  S rS	 rS
 rS rS r SS jrS rg)zNUseful commands for interacting with the Cloud Firestore Backup Schedules API.    )absolute_import)division)unicode_literals)	api_utils)arg_parsers)
exceptionsc                  @    [         R                  " 5       R                  $ )zDReturns the service to interact with the Firestore Backup Schedules.)r   	GetClient"projects_databases_backupSchedules     8lib/googlecloudsdk/api_lib/firestore/backup_schedules.py_GetBackupSchedulesServicer      s    					A	AAr   c           	          [         R                  " 5       n[        5       R                  UR	                  SR                  U UU5      S95      $ )zGets a backup schedule.

Args:
  project: the project of the database of the backup schedule, a string.
  database: the database id of the backup schedule, a string.
  backup_schedule: the backup schedule to read, a string.

Returns:
  a backup schedule.
+projects/{}/databases/{}/backupSchedules/{}name)r   GetMessagesr   Get3FirestoreProjectsDatabasesBackupSchedulesGetRequestformatprojectdatabasebackup_schedulemessagess       r   GetBackupScheduler      sS     ""$(	#	%	)	)BB<CC C 
 r   c           
          [         R                  " 5       n[        [        5       R	                  UR                  SR                  U U5      S95      R                  5      $ )zLists backup schedules under a database.

Args:
  project: the project of the database of the backup schedule, a string.
  database: the database id of the backup schedule, a string.

Returns:
  a list of backup schedules.
projects/{}/databases/{})parent)r   r   listr   List4FirestoreProjectsDatabasesBackupSchedulesListRequestr   backupSchedules)r   r   r   s      r   ListBackupSchedulesr%   6   s^     ""$(	 "t

G
G/66 H  
 r   c           	          [         R                  " 5       n[        5       R                  UR	                  SR                  U UU5      S95      $ )a	  Deletes a backup schedule.

Args:
  project: the project of the database of the backup schedule, a string.
  database: the database id of the backup schedule, a string.
  backup_schedule: the backup schedule to delete, a string.

Returns:
  Empty response message.
r   r   )r   r   r   Delete6FirestoreProjectsDatabasesBackupSchedulesDeleteRequestr   r   s       r   DeleteBackupScheduler)   O   sS     ""$(	#	%	,	,EE<CC F 
 r   c           	          [         R                  " 5       nUR                  5       nU(       a  [         R                  " U5      Ul        [        5       R                  UR                  SR                  U UU5      US95      $ )a  Updates a backup schedule.

Args:
  project: the project of the database of the backup schedule, a string.
  database: the database id of the backup schedule, a string.
  backup_schedule: the backup to read, a string.
  retention: the retention of the backup schedule, an int. At what relative
    time in the future, compared to the creation time of the backup should the
    backup be deleted. The unit is seconds.

Returns:
  a backup schedule.
r   )r   $googleFirestoreAdminV1BackupSchedule)	r   r   $GoogleFirestoreAdminV1BackupScheduleFormatDurationString	retentionr   Patch5FirestoreProjectsDatabasesBackupSchedulesPatchRequestr   )r   r   r   r.   r   backup_schedule_updatess         r   UpdateBackupScheduler2   f   s     ""$($IIK(1(F(F)% 
$	%	+	+DD<CC
 0G E 	
 	r   Nc                 H   [         R                  " 5       nUR                  5       n[         R                  " U5      Ul        US:X  a0  Ub  [
        R                  " SS5      eUR                  5       Ul        OvUS:X  aJ  Uc  [
        R                  " SS5      eUR                  5       Ul        [        U5      UR                  l        O&[
        R                  " SSR                  U5      5      e[!        5       R#                  UR%                  SR                  U U5      US	95      $ )
a  Creates a backup schedule.

Args:
  project: the project of the database of the backup schedule, a string.
  database: the database id of the backup schedule, a string.
  retention: the retention of the backup schedule, an int. At what relative
    time in the future, compared to the creation time of the backup should the
    backup be deleted. The unit is seconds.
  recurrence: the recurrence of the backup schedule, a string. The valid
    values are: daily and weekly.
  day_of_week: day of week for weekly backup schdeule.

Returns:
  a backup schedule.

Raises:
  InvalidArgumentException: if recurrence is invalid.
  ConflictingArgumentsException: if recurrence is daily but day-of-week is
  provided.
  RequiredArgumentException: if recurrence is weekly but day-of-week is not
  provided.
dailyz--day-of-weekz2Cannot set day of week for daily backup schedules.weeklyzcDay of week is required for weekly backup schedules, please use --day-of-week to specify this valuez--recurrencezGinvalid recurrence: {}. The available values are: `daily` and `weekly`.r   )r    r+   )r   r   r,   r-   r.   exConflictingArgumentsException%GoogleFirestoreAdminV1DailyRecurrencedailyRecurrenceRequiredArgumentException&GoogleFirestoreAdminV1WeeklyRecurrenceweeklyRecurrenceConvertDayOfWeekdayInvalidArgumentExceptionr   r   Create6FirestoreProjectsDatabasesBackupSchedulesCreateRequest)r   r   r.   
recurrenceday_of_weekr   r   s          r   CreateBackupSchedulerD      s0   2 ""$(AAC/'<<YG/7,,

> 
 	668 # X((
1  	779 $ ,<K+HO$$(

%
%	VJ'  
$	%	,	,EE+22 0? F 
 r   c                     [         R                  R                  R                  U 5      n[        R
                  " 5       R                  5       nUS:X  a  SnUR                  U5      $ )zConverts the user-given day-of-week into DayValueValuesEnum.

Args:
  day: day of Week for weekly backup schdeule.

Returns:
  DayValueValuesEnum.

Raises:
  ValueError: if it is an invalid input.
r      )r   	DayOfWeekDAYSindexr   r   r;   DayValueValuesEnum)r>   day_numr   s      r   r=   r=      sT     !!&&,,S1'""$KKM(\G		$	$W	--r   )N)__doc__
__future__r   r   r    googlecloudsdk.api_lib.firestorer   googlecloudsdk.callioper   r   r6   r   r   r%   r)   r2   rD   r=   r   r   r   <module>rP      sH    U &  ' 6 / 4B
.2.D ;??D.r   