{-# 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.CloudHSMV2.RestoreBackup
-- 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)
--
-- Restores a specified AWS CloudHSM backup that is in the
-- @PENDING_DELETION@ state. For mor information on deleting a backup, see
-- DeleteBackup.
module Amazonka.CloudHSMV2.RestoreBackup
  ( -- * Creating a Request
    RestoreBackup (..),
    newRestoreBackup,

    -- * Request Lenses
    restoreBackup_backupId,

    -- * Destructuring the Response
    RestoreBackupResponse (..),
    newRestoreBackupResponse,

    -- * Response Lenses
    restoreBackupResponse_backup,
    restoreBackupResponse_httpStatus,
  )
where

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

-- | /See:/ 'newRestoreBackup' smart constructor.
data RestoreBackup = RestoreBackup'
  { -- | The ID of the backup to be restored. To find the ID of a backup, use the
    -- DescribeBackups operation.
    RestoreBackup -> Text
backupId :: Prelude.Text
  }
  deriving (RestoreBackup -> RestoreBackup -> Bool
(RestoreBackup -> RestoreBackup -> Bool)
-> (RestoreBackup -> RestoreBackup -> Bool) -> Eq RestoreBackup
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RestoreBackup -> RestoreBackup -> Bool
$c/= :: RestoreBackup -> RestoreBackup -> Bool
== :: RestoreBackup -> RestoreBackup -> Bool
$c== :: RestoreBackup -> RestoreBackup -> Bool
Prelude.Eq, ReadPrec [RestoreBackup]
ReadPrec RestoreBackup
Int -> ReadS RestoreBackup
ReadS [RestoreBackup]
(Int -> ReadS RestoreBackup)
-> ReadS [RestoreBackup]
-> ReadPrec RestoreBackup
-> ReadPrec [RestoreBackup]
-> Read RestoreBackup
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RestoreBackup]
$creadListPrec :: ReadPrec [RestoreBackup]
readPrec :: ReadPrec RestoreBackup
$creadPrec :: ReadPrec RestoreBackup
readList :: ReadS [RestoreBackup]
$creadList :: ReadS [RestoreBackup]
readsPrec :: Int -> ReadS RestoreBackup
$creadsPrec :: Int -> ReadS RestoreBackup
Prelude.Read, Int -> RestoreBackup -> ShowS
[RestoreBackup] -> ShowS
RestoreBackup -> String
(Int -> RestoreBackup -> ShowS)
-> (RestoreBackup -> String)
-> ([RestoreBackup] -> ShowS)
-> Show RestoreBackup
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RestoreBackup] -> ShowS
$cshowList :: [RestoreBackup] -> ShowS
show :: RestoreBackup -> String
$cshow :: RestoreBackup -> String
showsPrec :: Int -> RestoreBackup -> ShowS
$cshowsPrec :: Int -> RestoreBackup -> ShowS
Prelude.Show, (forall x. RestoreBackup -> Rep RestoreBackup x)
-> (forall x. Rep RestoreBackup x -> RestoreBackup)
-> Generic RestoreBackup
forall x. Rep RestoreBackup x -> RestoreBackup
forall x. RestoreBackup -> Rep RestoreBackup x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RestoreBackup x -> RestoreBackup
$cfrom :: forall x. RestoreBackup -> Rep RestoreBackup x
Prelude.Generic)

-- |
-- Create a value of 'RestoreBackup' 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:
--
-- 'backupId', 'restoreBackup_backupId' - The ID of the backup to be restored. To find the ID of a backup, use the
-- DescribeBackups operation.
newRestoreBackup ::
  -- | 'backupId'
  Prelude.Text ->
  RestoreBackup
newRestoreBackup :: Text -> RestoreBackup
newRestoreBackup Text
pBackupId_ =
  RestoreBackup' :: Text -> RestoreBackup
RestoreBackup' {$sel:backupId:RestoreBackup' :: Text
backupId = Text
pBackupId_}

-- | The ID of the backup to be restored. To find the ID of a backup, use the
-- DescribeBackups operation.
restoreBackup_backupId :: Lens.Lens' RestoreBackup Prelude.Text
restoreBackup_backupId :: (Text -> f Text) -> RestoreBackup -> f RestoreBackup
restoreBackup_backupId = (RestoreBackup -> Text)
-> (RestoreBackup -> Text -> RestoreBackup)
-> Lens RestoreBackup RestoreBackup Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RestoreBackup' {Text
backupId :: Text
$sel:backupId:RestoreBackup' :: RestoreBackup -> Text
backupId} -> Text
backupId) (\s :: RestoreBackup
s@RestoreBackup' {} Text
a -> RestoreBackup
s {$sel:backupId:RestoreBackup' :: Text
backupId = Text
a} :: RestoreBackup)

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

instance Prelude.Hashable RestoreBackup

instance Prelude.NFData RestoreBackup

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

instance Core.ToJSON RestoreBackup where
  toJSON :: RestoreBackup -> Value
toJSON RestoreBackup' {Text
backupId :: Text
$sel:backupId:RestoreBackup' :: RestoreBackup -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"BackupId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
backupId)]
      )

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

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

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

-- |
-- Create a value of 'RestoreBackupResponse' 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:
--
-- 'backup', 'restoreBackupResponse_backup' - Information on the @Backup@ object created.
--
-- 'httpStatus', 'restoreBackupResponse_httpStatus' - The response's http status code.
newRestoreBackupResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  RestoreBackupResponse
newRestoreBackupResponse :: Int -> RestoreBackupResponse
newRestoreBackupResponse Int
pHttpStatus_ =
  RestoreBackupResponse' :: Maybe Backup -> Int -> RestoreBackupResponse
RestoreBackupResponse'
    { $sel:backup:RestoreBackupResponse' :: Maybe Backup
backup = Maybe Backup
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:RestoreBackupResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Information on the @Backup@ object created.
restoreBackupResponse_backup :: Lens.Lens' RestoreBackupResponse (Prelude.Maybe Backup)
restoreBackupResponse_backup :: (Maybe Backup -> f (Maybe Backup))
-> RestoreBackupResponse -> f RestoreBackupResponse
restoreBackupResponse_backup = (RestoreBackupResponse -> Maybe Backup)
-> (RestoreBackupResponse -> Maybe Backup -> RestoreBackupResponse)
-> Lens
     RestoreBackupResponse
     RestoreBackupResponse
     (Maybe Backup)
     (Maybe Backup)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RestoreBackupResponse' {Maybe Backup
backup :: Maybe Backup
$sel:backup:RestoreBackupResponse' :: RestoreBackupResponse -> Maybe Backup
backup} -> Maybe Backup
backup) (\s :: RestoreBackupResponse
s@RestoreBackupResponse' {} Maybe Backup
a -> RestoreBackupResponse
s {$sel:backup:RestoreBackupResponse' :: Maybe Backup
backup = Maybe Backup
a} :: RestoreBackupResponse)

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

instance Prelude.NFData RestoreBackupResponse