{-# 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.DynamoDB.CreateBackup
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Creates a backup for an existing table.
--
-- Each time you create an on-demand backup, the entire table data is
-- backed up. There is no limit to the number of on-demand backups that can
-- be taken.
--
-- When you create an on-demand backup, a time marker of the request is
-- cataloged, and the backup is created asynchronously, by applying all
-- changes until the time of the request to the last full table snapshot.
-- Backup requests are processed instantaneously and become available for
-- restore within minutes.
--
-- You can call @CreateBackup@ at a maximum rate of 50 times per second.
--
-- All backups in DynamoDB work without consuming any provisioned
-- throughput on the table.
--
-- If you submit a backup request on 2018-12-14 at 14:25:00, the backup is
-- guaranteed to contain all data committed to the table up to 14:24:00,
-- and data committed after 14:26:00 will not be. The backup might contain
-- data modifications made between 14:24:00 and 14:26:00. On-demand backup
-- does not support causal consistency.
--
-- Along with data, the following are also included on the backups:
--
-- -   Global secondary indexes (GSIs)
--
-- -   Local secondary indexes (LSIs)
--
-- -   Streams
--
-- -   Provisioned read and write capacity
module Amazonka.DynamoDB.CreateBackup
  ( -- * Creating a Request
    CreateBackup (..),
    newCreateBackup,

    -- * Request Lenses
    createBackup_tableName,
    createBackup_backupName,

    -- * Destructuring the Response
    CreateBackupResponse (..),
    newCreateBackupResponse,

    -- * Response Lenses
    createBackupResponse_backupDetails,
    createBackupResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.DynamoDB.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newCreateBackup' smart constructor.
data CreateBackup = CreateBackup'
  { -- | The name of the table.
    CreateBackup -> Text
tableName :: Prelude.Text,
    -- | Specified name for the backup.
    CreateBackup -> Text
backupName :: Prelude.Text
  }
  deriving (CreateBackup -> CreateBackup -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateBackup -> CreateBackup -> Bool
$c/= :: CreateBackup -> CreateBackup -> Bool
== :: CreateBackup -> CreateBackup -> Bool
$c== :: CreateBackup -> CreateBackup -> Bool
Prelude.Eq, ReadPrec [CreateBackup]
ReadPrec CreateBackup
Int -> ReadS CreateBackup
ReadS [CreateBackup]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateBackup]
$creadListPrec :: ReadPrec [CreateBackup]
readPrec :: ReadPrec CreateBackup
$creadPrec :: ReadPrec CreateBackup
readList :: ReadS [CreateBackup]
$creadList :: ReadS [CreateBackup]
readsPrec :: Int -> ReadS CreateBackup
$creadsPrec :: Int -> ReadS CreateBackup
Prelude.Read, Int -> CreateBackup -> ShowS
[CreateBackup] -> ShowS
CreateBackup -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateBackup] -> ShowS
$cshowList :: [CreateBackup] -> ShowS
show :: CreateBackup -> String
$cshow :: CreateBackup -> String
showsPrec :: Int -> CreateBackup -> ShowS
$cshowsPrec :: Int -> CreateBackup -> ShowS
Prelude.Show, forall x. Rep CreateBackup x -> CreateBackup
forall x. CreateBackup -> Rep CreateBackup x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateBackup x -> CreateBackup
$cfrom :: forall x. CreateBackup -> Rep CreateBackup x
Prelude.Generic)

-- |
-- Create a value of 'CreateBackup' 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:
--
-- 'tableName', 'createBackup_tableName' - The name of the table.
--
-- 'backupName', 'createBackup_backupName' - Specified name for the backup.
newCreateBackup ::
  -- | 'tableName'
  Prelude.Text ->
  -- | 'backupName'
  Prelude.Text ->
  CreateBackup
newCreateBackup :: Text -> Text -> CreateBackup
newCreateBackup Text
pTableName_ Text
pBackupName_ =
  CreateBackup'
    { $sel:tableName:CreateBackup' :: Text
tableName = Text
pTableName_,
      $sel:backupName:CreateBackup' :: Text
backupName = Text
pBackupName_
    }

-- | The name of the table.
createBackup_tableName :: Lens.Lens' CreateBackup Prelude.Text
createBackup_tableName :: Lens' CreateBackup Text
createBackup_tableName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateBackup' {Text
tableName :: Text
$sel:tableName:CreateBackup' :: CreateBackup -> Text
tableName} -> Text
tableName) (\s :: CreateBackup
s@CreateBackup' {} Text
a -> CreateBackup
s {$sel:tableName:CreateBackup' :: Text
tableName = Text
a} :: CreateBackup)

-- | Specified name for the backup.
createBackup_backupName :: Lens.Lens' CreateBackup Prelude.Text
createBackup_backupName :: Lens' CreateBackup Text
createBackup_backupName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateBackup' {Text
backupName :: Text
$sel:backupName:CreateBackup' :: CreateBackup -> Text
backupName} -> Text
backupName) (\s :: CreateBackup
s@CreateBackup' {} Text
a -> CreateBackup
s {$sel:backupName:CreateBackup' :: Text
backupName = Text
a} :: CreateBackup)

instance Core.AWSRequest CreateBackup where
  type AWSResponse CreateBackup = CreateBackupResponse
  request :: (Service -> Service) -> CreateBackup -> Request CreateBackup
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy CreateBackup
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateBackup)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe BackupDetails -> Int -> CreateBackupResponse
CreateBackupResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"BackupDetails")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable CreateBackup where
  hashWithSalt :: Int -> CreateBackup -> Int
hashWithSalt Int
_salt CreateBackup' {Text
backupName :: Text
tableName :: Text
$sel:backupName:CreateBackup' :: CreateBackup -> Text
$sel:tableName:CreateBackup' :: CreateBackup -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
tableName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
backupName

instance Prelude.NFData CreateBackup where
  rnf :: CreateBackup -> ()
rnf CreateBackup' {Text
backupName :: Text
tableName :: Text
$sel:backupName:CreateBackup' :: CreateBackup -> Text
$sel:tableName:CreateBackup' :: CreateBackup -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
tableName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
backupName

instance Data.ToHeaders CreateBackup where
  toHeaders :: CreateBackup -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"DynamoDB_20120810.CreateBackup" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.0" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON CreateBackup where
  toJSON :: CreateBackup -> Value
toJSON CreateBackup' {Text
backupName :: Text
tableName :: Text
$sel:backupName:CreateBackup' :: CreateBackup -> Text
$sel:tableName:CreateBackup' :: CreateBackup -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"TableName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
tableName),
            forall a. a -> Maybe a
Prelude.Just (Key
"BackupName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
backupName)
          ]
      )

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

instance Data.ToQuery CreateBackup where
  toQuery :: CreateBackup -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newCreateBackupResponse' smart constructor.
data CreateBackupResponse = CreateBackupResponse'
  { -- | Contains the details of the backup created for the table.
    CreateBackupResponse -> Maybe BackupDetails
backupDetails :: Prelude.Maybe BackupDetails,
    -- | The response's http status code.
    CreateBackupResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CreateBackupResponse -> CreateBackupResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateBackupResponse -> CreateBackupResponse -> Bool
$c/= :: CreateBackupResponse -> CreateBackupResponse -> Bool
== :: CreateBackupResponse -> CreateBackupResponse -> Bool
$c== :: CreateBackupResponse -> CreateBackupResponse -> Bool
Prelude.Eq, ReadPrec [CreateBackupResponse]
ReadPrec CreateBackupResponse
Int -> ReadS CreateBackupResponse
ReadS [CreateBackupResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateBackupResponse]
$creadListPrec :: ReadPrec [CreateBackupResponse]
readPrec :: ReadPrec CreateBackupResponse
$creadPrec :: ReadPrec CreateBackupResponse
readList :: ReadS [CreateBackupResponse]
$creadList :: ReadS [CreateBackupResponse]
readsPrec :: Int -> ReadS CreateBackupResponse
$creadsPrec :: Int -> ReadS CreateBackupResponse
Prelude.Read, Int -> CreateBackupResponse -> ShowS
[CreateBackupResponse] -> ShowS
CreateBackupResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateBackupResponse] -> ShowS
$cshowList :: [CreateBackupResponse] -> ShowS
show :: CreateBackupResponse -> String
$cshow :: CreateBackupResponse -> String
showsPrec :: Int -> CreateBackupResponse -> ShowS
$cshowsPrec :: Int -> CreateBackupResponse -> ShowS
Prelude.Show, forall x. Rep CreateBackupResponse x -> CreateBackupResponse
forall x. CreateBackupResponse -> Rep CreateBackupResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateBackupResponse x -> CreateBackupResponse
$cfrom :: forall x. CreateBackupResponse -> Rep CreateBackupResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateBackupResponse' 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:
--
-- 'backupDetails', 'createBackupResponse_backupDetails' - Contains the details of the backup created for the table.
--
-- 'httpStatus', 'createBackupResponse_httpStatus' - The response's http status code.
newCreateBackupResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateBackupResponse
newCreateBackupResponse :: Int -> CreateBackupResponse
newCreateBackupResponse Int
pHttpStatus_ =
  CreateBackupResponse'
    { $sel:backupDetails:CreateBackupResponse' :: Maybe BackupDetails
backupDetails =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateBackupResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Contains the details of the backup created for the table.
createBackupResponse_backupDetails :: Lens.Lens' CreateBackupResponse (Prelude.Maybe BackupDetails)
createBackupResponse_backupDetails :: Lens' CreateBackupResponse (Maybe BackupDetails)
createBackupResponse_backupDetails = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateBackupResponse' {Maybe BackupDetails
backupDetails :: Maybe BackupDetails
$sel:backupDetails:CreateBackupResponse' :: CreateBackupResponse -> Maybe BackupDetails
backupDetails} -> Maybe BackupDetails
backupDetails) (\s :: CreateBackupResponse
s@CreateBackupResponse' {} Maybe BackupDetails
a -> CreateBackupResponse
s {$sel:backupDetails:CreateBackupResponse' :: Maybe BackupDetails
backupDetails = Maybe BackupDetails
a} :: CreateBackupResponse)

-- | The response's http status code.
createBackupResponse_httpStatus :: Lens.Lens' CreateBackupResponse Prelude.Int
createBackupResponse_httpStatus :: Lens' CreateBackupResponse Int
createBackupResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateBackupResponse' {Int
httpStatus :: Int
$sel:httpStatus:CreateBackupResponse' :: CreateBackupResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: CreateBackupResponse
s@CreateBackupResponse' {} Int
a -> CreateBackupResponse
s {$sel:httpStatus:CreateBackupResponse' :: Int
httpStatus = Int
a} :: CreateBackupResponse)

instance Prelude.NFData CreateBackupResponse where
  rnf :: CreateBackupResponse -> ()
rnf CreateBackupResponse' {Int
Maybe BackupDetails
httpStatus :: Int
backupDetails :: Maybe BackupDetails
$sel:httpStatus:CreateBackupResponse' :: CreateBackupResponse -> Int
$sel:backupDetails:CreateBackupResponse' :: CreateBackupResponse -> Maybe BackupDetails
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe BackupDetails
backupDetails
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus