
    &                        d 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 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 ddlZdZdZeedZej0                   ej2                  ej4                  j6                         G d dej8                                      Zej0                   ej2                  ej4                  j<                  ej4                  j>                         G d dej8                                      Z y)z=Retrieves the latest recovery time for a Cloud SQL instance.
    )absolute_import)division)unicode_literals)
exceptions)api_util)validate)arg_parsers)base)flags)
propertiesNz
    *{command}* retrieves the latest recovery time for a Cloud SQL instance.
    This is the latest time that can be used to perform point in time recovery
    for the Cloud SQL instance.
    a      To retrieve the latest recovery time for an instance:

    $ {command} instance-foo

    To retrieve the latest recovery time for an instance that has been deleted:

    $ {command} instance-foo --source-instance-deletion-time '2012-11-15T16:19:00.094Z'
    )DESCRIPTIONEXAMPLESc                   *    e Zd ZdZeZed        Zd Zy)GetLatestRecoveryTimeVDisplays the latest recovery time to which a Cloud SQL instance can be restored to.
  c                     | j                  dt        j                  d       | j                  dt        j                  j
                  t        j                  dd       y	zArgs is called by calliope to gather arguments for this command.

    Args:
      parser: An argparse parser that you can use it to add arguments that go on
        the command line after this command. Positional arguments are allowed.
    instancezCloud SQL instance ID.)	completerhelpz--source-instance-deletion-timeFzgThe deletion time of the source instance. This is used to identify the instance if it has been deleted.)typer   requiredr   Nadd_argumentr   InstanceCompleterr	   DatetimeParseparsers    5lib/surface/sql/instances/get_latest_recovery_time.pyArgszGetLatestRecoveryTime.ArgsA   ^     ))%  ' )!!''))4  	    c                 f   t        j                  t         j                        }|j                  }|j                  }t        j                  |j                         |j                  j                  |j                  dt        j                  j                  j                  j                  id      }	 |j                  |j                  |j                        }|j                   r |j                   j#                  d      |_        |j&                  j)                  |      S # t*        j,                  $ r}}|j.                  t0        j2                  j4                  j6                  k(  r2t9        j:                  dj=                  |j?                                     tA        jB                  |      d}~ww xY wa  Displays the latest recovery time to which a Cloud SQL instance can be restored to.

    Args:
      args: argparse.Namespace, The arguments that this command was invoked
        with.

    Returns:
      A timestamp representing the latest recovery time to which a Cloud SQL
      instance can be restored to.

    Raises:
      HttpException: A http error response was received while executing api
          request.
      ResourceNotFoundError: The SQL instance isn't found.
    projectzsql.instances)params
collection)r&   r   z%Y-%m-%dT%H:%M:%S.%fZzFThere's no instance found at {} or you're not authorized to access it.N"r   	SqlClientAPI_VERSION_DEFAULT
sql_clientsql_messagesr   ValidateInstanceNamer   resource_parserr   r   VALUEScorer&   	GetOrFail0SqlProjectsInstancesGetLatestRecoveryTimeRequestsource_instance_deletion_timestrftimesourceInstanceDeletionTimeprojects_instancesr   apitools_exceptions	HttpErrorstatus_codesixmoveshttp_client	FORBIDDENr   ResourceNotFoundErrorformatRelativeNamecalliope_exceptionsHttpExceptionselfargsclientr,   r-   instance_refrequesterrors           r    RunzGetLatestRecoveryTime.RunX   e      < <=F""J&&L!!$--0))//:,,1199CCD" 0 $L5MM&&1F1F N Hg		+	+..778OP 	* **@@II(( 5			cii33==	=.. 9 9 ;<> 	>  --e445   2A-D   F03A8F++F0N	__name__
__module____qualname____doc__DETAILED_HELPdetailed_helpstaticmethodr!   rK    r#   r    r   r   9   %      - ,&5r#   r   c                   *    e Zd ZdZeZed        Zd Zy)GetLatestRecoveryTimeBetar   c                     | j                  dt        j                  d       | j                  dt        j                  j
                  t        j                  dd       yr   r   r   s    r    r!   zGetLatestRecoveryTimeBeta.Args   r"   r#   c                 f   t        j                  t         j                        }|j                  }|j                  }t        j                  |j                         |j                  j                  |j                  dt        j                  j                  j                  j                  id      }	 |j                  |j                  |j                        }|j                   r |j                   j#                  d      |_        |j&                  j)                  |      S # t*        j,                  $ r}}|j.                  t0        j2                  j4                  j6                  k(  r2t9        j:                  dj=                  |j?                                     tA        jB                  |      d}~ww xY wr%   r)   rD   s           r    rK   zGetLatestRecoveryTimeBeta.Run   rL   rM   NrN   rV   r#   r    rY   rY      rW   r#   rY   )!rR   
__future__r   r   r   apitools.base.pyr   r8   googlecloudsdk.api_lib.sqlr   r   googlecloudsdk.callioper	   r
   rB   googlecloudsdk.command_lib.sqlr   googlecloudsdk.corer   six.moves.http_clientr;   r   EXAMPLES_GArS   DefaultUniverseOnlyReleaseTracksReleaseTrackGACommandr   BETAALPHArY   rV   r#   r    <module>rk      s    '  ' > / 1 / / ( E 0 *   D%%(()C5DLL C5 * C5L D%%**D,=,=,C,CDC5 C5 E C5r#   