{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.RDS.BacktrackDBCluster
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Backtracks a DB cluster to a specific time, without creating a new DB
-- cluster.
--
-- For more information on backtracking, see
-- <https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraMySQL.Managing.Backtrack.html Backtracking an Aurora DB Cluster>
-- in the /Amazon Aurora User Guide./
--
-- This action only applies to Aurora MySQL DB clusters.
module Amazonka.RDS.BacktrackDBCluster
  ( -- * Creating a Request
    BacktrackDBCluster (..),
    newBacktrackDBCluster,

    -- * Request Lenses
    backtrackDBCluster_force,
    backtrackDBCluster_useEarliestTimeOnPointInTimeUnavailable,
    backtrackDBCluster_dbClusterIdentifier,
    backtrackDBCluster_backtrackTo,

    -- * Destructuring the Response
    DBClusterBacktrack (..),
    newDBClusterBacktrack,

    -- * Response Lenses
    dbClusterBacktrack_status,
    dbClusterBacktrack_backtrackIdentifier,
    dbClusterBacktrack_backtrackTo,
    dbClusterBacktrack_dbClusterIdentifier,
    dbClusterBacktrack_backtrackedFrom,
    dbClusterBacktrack_backtrackRequestCreationTime,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.RDS.Types
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- |
--
-- /See:/ 'newBacktrackDBCluster' smart constructor.
data BacktrackDBCluster = BacktrackDBCluster'
  { -- | A value that indicates whether to force the DB cluster to backtrack when
    -- binary logging is enabled. Otherwise, an error occurs when binary
    -- logging is enabled.
    BacktrackDBCluster -> Maybe Bool
force :: Prelude.Maybe Prelude.Bool,
    -- | A value that indicates whether to backtrack the DB cluster to the
    -- earliest possible backtrack time when /BacktrackTo/ is set to a
    -- timestamp earlier than the earliest backtrack time. When this parameter
    -- is disabled and /BacktrackTo/ is set to a timestamp earlier than the
    -- earliest backtrack time, an error occurs.
    BacktrackDBCluster -> Maybe Bool
useEarliestTimeOnPointInTimeUnavailable :: Prelude.Maybe Prelude.Bool,
    -- | The DB cluster identifier of the DB cluster to be backtracked. This
    -- parameter is stored as a lowercase string.
    --
    -- Constraints:
    --
    -- -   Must contain from 1 to 63 alphanumeric characters or hyphens.
    --
    -- -   First character must be a letter.
    --
    -- -   Can\'t end with a hyphen or contain two consecutive hyphens.
    --
    -- Example: @my-cluster1@
    BacktrackDBCluster -> Text
dbClusterIdentifier :: Prelude.Text,
    -- | The timestamp of the time to backtrack the DB cluster to, specified in
    -- ISO 8601 format. For more information about ISO 8601, see the
    -- <http://en.wikipedia.org/wiki/ISO_8601 ISO8601 Wikipedia page.>
    --
    -- If the specified time isn\'t a consistent time for the DB cluster,
    -- Aurora automatically chooses the nearest possible consistent time for
    -- the DB cluster.
    --
    -- Constraints:
    --
    -- -   Must contain a valid ISO 8601 timestamp.
    --
    -- -   Can\'t contain a timestamp set in the future.
    --
    -- Example: @2017-07-08T18:00Z@
    BacktrackDBCluster -> ISO8601
backtrackTo :: Core.ISO8601
  }
  deriving (BacktrackDBCluster -> BacktrackDBCluster -> Bool
(BacktrackDBCluster -> BacktrackDBCluster -> Bool)
-> (BacktrackDBCluster -> BacktrackDBCluster -> Bool)
-> Eq BacktrackDBCluster
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BacktrackDBCluster -> BacktrackDBCluster -> Bool
$c/= :: BacktrackDBCluster -> BacktrackDBCluster -> Bool
== :: BacktrackDBCluster -> BacktrackDBCluster -> Bool
$c== :: BacktrackDBCluster -> BacktrackDBCluster -> Bool
Prelude.Eq, ReadPrec [BacktrackDBCluster]
ReadPrec BacktrackDBCluster
Int -> ReadS BacktrackDBCluster
ReadS [BacktrackDBCluster]
(Int -> ReadS BacktrackDBCluster)
-> ReadS [BacktrackDBCluster]
-> ReadPrec BacktrackDBCluster
-> ReadPrec [BacktrackDBCluster]
-> Read BacktrackDBCluster
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BacktrackDBCluster]
$creadListPrec :: ReadPrec [BacktrackDBCluster]
readPrec :: ReadPrec BacktrackDBCluster
$creadPrec :: ReadPrec BacktrackDBCluster
readList :: ReadS [BacktrackDBCluster]
$creadList :: ReadS [BacktrackDBCluster]
readsPrec :: Int -> ReadS BacktrackDBCluster
$creadsPrec :: Int -> ReadS BacktrackDBCluster
Prelude.Read, Int -> BacktrackDBCluster -> ShowS
[BacktrackDBCluster] -> ShowS
BacktrackDBCluster -> String
(Int -> BacktrackDBCluster -> ShowS)
-> (BacktrackDBCluster -> String)
-> ([BacktrackDBCluster] -> ShowS)
-> Show BacktrackDBCluster
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BacktrackDBCluster] -> ShowS
$cshowList :: [BacktrackDBCluster] -> ShowS
show :: BacktrackDBCluster -> String
$cshow :: BacktrackDBCluster -> String
showsPrec :: Int -> BacktrackDBCluster -> ShowS
$cshowsPrec :: Int -> BacktrackDBCluster -> ShowS
Prelude.Show, (forall x. BacktrackDBCluster -> Rep BacktrackDBCluster x)
-> (forall x. Rep BacktrackDBCluster x -> BacktrackDBCluster)
-> Generic BacktrackDBCluster
forall x. Rep BacktrackDBCluster x -> BacktrackDBCluster
forall x. BacktrackDBCluster -> Rep BacktrackDBCluster x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BacktrackDBCluster x -> BacktrackDBCluster
$cfrom :: forall x. BacktrackDBCluster -> Rep BacktrackDBCluster x
Prelude.Generic)

-- |
-- Create a value of 'BacktrackDBCluster' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'force', 'backtrackDBCluster_force' - A value that indicates whether to force the DB cluster to backtrack when
-- binary logging is enabled. Otherwise, an error occurs when binary
-- logging is enabled.
--
-- 'useEarliestTimeOnPointInTimeUnavailable', 'backtrackDBCluster_useEarliestTimeOnPointInTimeUnavailable' - A value that indicates whether to backtrack the DB cluster to the
-- earliest possible backtrack time when /BacktrackTo/ is set to a
-- timestamp earlier than the earliest backtrack time. When this parameter
-- is disabled and /BacktrackTo/ is set to a timestamp earlier than the
-- earliest backtrack time, an error occurs.
--
-- 'dbClusterIdentifier', 'backtrackDBCluster_dbClusterIdentifier' - The DB cluster identifier of the DB cluster to be backtracked. This
-- parameter is stored as a lowercase string.
--
-- Constraints:
--
-- -   Must contain from 1 to 63 alphanumeric characters or hyphens.
--
-- -   First character must be a letter.
--
-- -   Can\'t end with a hyphen or contain two consecutive hyphens.
--
-- Example: @my-cluster1@
--
-- 'backtrackTo', 'backtrackDBCluster_backtrackTo' - The timestamp of the time to backtrack the DB cluster to, specified in
-- ISO 8601 format. For more information about ISO 8601, see the
-- <http://en.wikipedia.org/wiki/ISO_8601 ISO8601 Wikipedia page.>
--
-- If the specified time isn\'t a consistent time for the DB cluster,
-- Aurora automatically chooses the nearest possible consistent time for
-- the DB cluster.
--
-- Constraints:
--
-- -   Must contain a valid ISO 8601 timestamp.
--
-- -   Can\'t contain a timestamp set in the future.
--
-- Example: @2017-07-08T18:00Z@
newBacktrackDBCluster ::
  -- | 'dbClusterIdentifier'
  Prelude.Text ->
  -- | 'backtrackTo'
  Prelude.UTCTime ->
  BacktrackDBCluster
newBacktrackDBCluster :: Text -> UTCTime -> BacktrackDBCluster
newBacktrackDBCluster
  Text
pDBClusterIdentifier_
  UTCTime
pBacktrackTo_ =
    BacktrackDBCluster' :: Maybe Bool -> Maybe Bool -> Text -> ISO8601 -> BacktrackDBCluster
BacktrackDBCluster'
      { $sel:force:BacktrackDBCluster' :: Maybe Bool
force = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
        $sel:useEarliestTimeOnPointInTimeUnavailable:BacktrackDBCluster' :: Maybe Bool
useEarliestTimeOnPointInTimeUnavailable =
          Maybe Bool
forall a. Maybe a
Prelude.Nothing,
        $sel:dbClusterIdentifier:BacktrackDBCluster' :: Text
dbClusterIdentifier = Text
pDBClusterIdentifier_,
        $sel:backtrackTo:BacktrackDBCluster' :: ISO8601
backtrackTo = Tagged UTCTime (Identity UTCTime)
-> Tagged ISO8601 (Identity ISO8601)
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time (Tagged UTCTime (Identity UTCTime)
 -> Tagged ISO8601 (Identity ISO8601))
-> UTCTime -> ISO8601
forall t b. AReview t b -> b -> t
Lens.# UTCTime
pBacktrackTo_
      }

-- | A value that indicates whether to force the DB cluster to backtrack when
-- binary logging is enabled. Otherwise, an error occurs when binary
-- logging is enabled.
backtrackDBCluster_force :: Lens.Lens' BacktrackDBCluster (Prelude.Maybe Prelude.Bool)
backtrackDBCluster_force :: (Maybe Bool -> f (Maybe Bool))
-> BacktrackDBCluster -> f BacktrackDBCluster
backtrackDBCluster_force = (BacktrackDBCluster -> Maybe Bool)
-> (BacktrackDBCluster -> Maybe Bool -> BacktrackDBCluster)
-> Lens
     BacktrackDBCluster BacktrackDBCluster (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BacktrackDBCluster' {Maybe Bool
force :: Maybe Bool
$sel:force:BacktrackDBCluster' :: BacktrackDBCluster -> Maybe Bool
force} -> Maybe Bool
force) (\s :: BacktrackDBCluster
s@BacktrackDBCluster' {} Maybe Bool
a -> BacktrackDBCluster
s {$sel:force:BacktrackDBCluster' :: Maybe Bool
force = Maybe Bool
a} :: BacktrackDBCluster)

-- | A value that indicates whether to backtrack the DB cluster to the
-- earliest possible backtrack time when /BacktrackTo/ is set to a
-- timestamp earlier than the earliest backtrack time. When this parameter
-- is disabled and /BacktrackTo/ is set to a timestamp earlier than the
-- earliest backtrack time, an error occurs.
backtrackDBCluster_useEarliestTimeOnPointInTimeUnavailable :: Lens.Lens' BacktrackDBCluster (Prelude.Maybe Prelude.Bool)
backtrackDBCluster_useEarliestTimeOnPointInTimeUnavailable :: (Maybe Bool -> f (Maybe Bool))
-> BacktrackDBCluster -> f BacktrackDBCluster
backtrackDBCluster_useEarliestTimeOnPointInTimeUnavailable = (BacktrackDBCluster -> Maybe Bool)
-> (BacktrackDBCluster -> Maybe Bool -> BacktrackDBCluster)
-> Lens
     BacktrackDBCluster BacktrackDBCluster (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BacktrackDBCluster' {Maybe Bool
useEarliestTimeOnPointInTimeUnavailable :: Maybe Bool
$sel:useEarliestTimeOnPointInTimeUnavailable:BacktrackDBCluster' :: BacktrackDBCluster -> Maybe Bool
useEarliestTimeOnPointInTimeUnavailable} -> Maybe Bool
useEarliestTimeOnPointInTimeUnavailable) (\s :: BacktrackDBCluster
s@BacktrackDBCluster' {} Maybe Bool
a -> BacktrackDBCluster
s {$sel:useEarliestTimeOnPointInTimeUnavailable:BacktrackDBCluster' :: Maybe Bool
useEarliestTimeOnPointInTimeUnavailable = Maybe Bool
a} :: BacktrackDBCluster)

-- | The DB cluster identifier of the DB cluster to be backtracked. This
-- parameter is stored as a lowercase string.
--
-- Constraints:
--
-- -   Must contain from 1 to 63 alphanumeric characters or hyphens.
--
-- -   First character must be a letter.
--
-- -   Can\'t end with a hyphen or contain two consecutive hyphens.
--
-- Example: @my-cluster1@
backtrackDBCluster_dbClusterIdentifier :: Lens.Lens' BacktrackDBCluster Prelude.Text
backtrackDBCluster_dbClusterIdentifier :: (Text -> f Text) -> BacktrackDBCluster -> f BacktrackDBCluster
backtrackDBCluster_dbClusterIdentifier = (BacktrackDBCluster -> Text)
-> (BacktrackDBCluster -> Text -> BacktrackDBCluster)
-> Lens BacktrackDBCluster BacktrackDBCluster Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BacktrackDBCluster' {Text
dbClusterIdentifier :: Text
$sel:dbClusterIdentifier:BacktrackDBCluster' :: BacktrackDBCluster -> Text
dbClusterIdentifier} -> Text
dbClusterIdentifier) (\s :: BacktrackDBCluster
s@BacktrackDBCluster' {} Text
a -> BacktrackDBCluster
s {$sel:dbClusterIdentifier:BacktrackDBCluster' :: Text
dbClusterIdentifier = Text
a} :: BacktrackDBCluster)

-- | The timestamp of the time to backtrack the DB cluster to, specified in
-- ISO 8601 format. For more information about ISO 8601, see the
-- <http://en.wikipedia.org/wiki/ISO_8601 ISO8601 Wikipedia page.>
--
-- If the specified time isn\'t a consistent time for the DB cluster,
-- Aurora automatically chooses the nearest possible consistent time for
-- the DB cluster.
--
-- Constraints:
--
-- -   Must contain a valid ISO 8601 timestamp.
--
-- -   Can\'t contain a timestamp set in the future.
--
-- Example: @2017-07-08T18:00Z@
backtrackDBCluster_backtrackTo :: Lens.Lens' BacktrackDBCluster Prelude.UTCTime
backtrackDBCluster_backtrackTo :: (UTCTime -> f UTCTime)
-> BacktrackDBCluster -> f BacktrackDBCluster
backtrackDBCluster_backtrackTo = (BacktrackDBCluster -> ISO8601)
-> (BacktrackDBCluster -> ISO8601 -> BacktrackDBCluster)
-> Lens BacktrackDBCluster BacktrackDBCluster ISO8601 ISO8601
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BacktrackDBCluster' {ISO8601
backtrackTo :: ISO8601
$sel:backtrackTo:BacktrackDBCluster' :: BacktrackDBCluster -> ISO8601
backtrackTo} -> ISO8601
backtrackTo) (\s :: BacktrackDBCluster
s@BacktrackDBCluster' {} ISO8601
a -> BacktrackDBCluster
s {$sel:backtrackTo:BacktrackDBCluster' :: ISO8601
backtrackTo = ISO8601
a} :: BacktrackDBCluster) ((ISO8601 -> f ISO8601)
 -> BacktrackDBCluster -> f BacktrackDBCluster)
-> ((UTCTime -> f UTCTime) -> ISO8601 -> f ISO8601)
-> (UTCTime -> f UTCTime)
-> BacktrackDBCluster
-> f BacktrackDBCluster
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (UTCTime -> f UTCTime) -> ISO8601 -> f ISO8601
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

instance Core.AWSRequest BacktrackDBCluster where
  type
    AWSResponse BacktrackDBCluster =
      DBClusterBacktrack
  request :: BacktrackDBCluster -> Request BacktrackDBCluster
request = Service -> BacktrackDBCluster -> Request BacktrackDBCluster
forall a. ToRequest a => Service -> a -> Request a
Request.postQuery Service
defaultService
  response :: Logger
-> Service
-> Proxy BacktrackDBCluster
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse BacktrackDBCluster)))
response =
    Text
-> (Int
    -> ResponseHeaders
    -> [Node]
    -> Either String (AWSResponse BacktrackDBCluster))
-> Logger
-> Service
-> Proxy BacktrackDBCluster
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse BacktrackDBCluster)))
forall (m :: * -> *) a.
MonadResource m =>
Text
-> (Int
    -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveXMLWrapper
      Text
"BacktrackDBClusterResult"
      (\Int
s ResponseHeaders
h [Node]
x -> [Node] -> Either String DBClusterBacktrack
forall a. FromXML a => [Node] -> Either String a
Core.parseXML [Node]
x)

instance Prelude.Hashable BacktrackDBCluster

instance Prelude.NFData BacktrackDBCluster

instance Core.ToHeaders BacktrackDBCluster where
  toHeaders :: BacktrackDBCluster -> ResponseHeaders
toHeaders = ResponseHeaders -> BacktrackDBCluster -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const ResponseHeaders
forall a. Monoid a => a
Prelude.mempty

instance Core.ToPath BacktrackDBCluster where
  toPath :: BacktrackDBCluster -> ByteString
toPath = ByteString -> BacktrackDBCluster -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Core.ToQuery BacktrackDBCluster where
  toQuery :: BacktrackDBCluster -> QueryString
toQuery BacktrackDBCluster' {Maybe Bool
Text
ISO8601
backtrackTo :: ISO8601
dbClusterIdentifier :: Text
useEarliestTimeOnPointInTimeUnavailable :: Maybe Bool
force :: Maybe Bool
$sel:backtrackTo:BacktrackDBCluster' :: BacktrackDBCluster -> ISO8601
$sel:dbClusterIdentifier:BacktrackDBCluster' :: BacktrackDBCluster -> Text
$sel:useEarliestTimeOnPointInTimeUnavailable:BacktrackDBCluster' :: BacktrackDBCluster -> Maybe Bool
$sel:force:BacktrackDBCluster' :: BacktrackDBCluster -> Maybe Bool
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"BacktrackDBCluster" :: Prelude.ByteString),
        ByteString
"Version"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"2014-10-31" :: Prelude.ByteString),
        ByteString
"Force" ByteString -> Maybe Bool -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Bool
force,
        ByteString
"UseEarliestTimeOnPointInTimeUnavailable"
          ByteString -> Maybe Bool -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Bool
useEarliestTimeOnPointInTimeUnavailable,
        ByteString
"DBClusterIdentifier" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
dbClusterIdentifier,
        ByteString
"BacktrackTo" ByteString -> ISO8601 -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: ISO8601
backtrackTo
      ]