
                             d Z ddlZddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddl	mZ  G d	 d
e
j                        Zy)z$The undelete command for the BQ CLI.    N)app)flags)client_dataset)utils)bigquery_command)bq_cached_clientc                   P     e Zd ZdZdZdedej                  f fdZdefdZ	 xZ
S )Undeletez-Undelete the dataset described by identifier.zbq undelete datasetnamefvc                 z    t         |   ||       t        j                  dd d|       | j	                  |       y )N	timestampzOptional. Time in milliseconds since the POSIX epoch that this replica was marked for deletion. If not specified, it will undelete the most recently deleted version.)flag_values)super__init__r   DEFINE_integer_ProcessCommandRc)selfr   r   	__class__s      (platform/bq/frontend/command_undelete.pyr   zUndelete.__init__   s@    	GT2		%  	2    
identifierc                    t         j                  j                         }|st        j                  d      t        j                  ||      }| j                  rGt        j                  j                  | j                  dz  t        j                  j                        }nd}t        j                  |j                  ||      }|rt        d|d       yy)	a  Undelete the dataset described by identifier.

    Always requires an identifier, unlike the show and ls commands.
    By default, also requires confirmation before undeleting.
    Supports:
     - timestamp[int]: This signifies the timestamp version of the dataset that
     needs to be restored, this should be in milliseconds

    Examples:
      bq undelete dataset
      bq undelete --timestamp 1714720875568 dataset
    z(Must provide an identifier for undelete.)id_fallbacksr   i  )tzN)r   zDataset undelete of z successfully started)r   ClientGetr   
UsageErrorbq_client_utilsGetDatasetReferencer   datetimefromtimestamptimezoneutcr   UndeleteDataset	apiclientprint)r   r   clientdatasetr   jobs         r   RunWithArgszUndelete.RunWithArgs#   s     $$((*FNNEFF11
G ~~##11
..4
H$5$5$9$9 2 i i

(
('YC WFG r   )__name__
__module____qualname____doc__usagestrr   
FlagValuesr   r+   __classcell__)r   s   @r   r
   r
      s2    5
#%
3 
E$4$4 
HC Hr   r
   )r/   r!   abslr   r   clientsr   r   r   frontendr   r   BigqueryCmdr
    r   r   <module>r9      s2    *    " , % %/H++ /Hr   