{-# 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.DirectoryService.RestoreFromSnapshot
-- 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 directory using an existing directory snapshot.
--
-- When you restore a directory from a snapshot, any changes made to the
-- directory after the snapshot date are overwritten.
--
-- This action returns as soon as the restore operation is initiated. You
-- can monitor the progress of the restore operation by calling the
-- DescribeDirectories operation with the directory identifier. When the
-- __DirectoryDescription.Stage__ value changes to @Active@, the restore
-- operation is complete.
module Amazonka.DirectoryService.RestoreFromSnapshot
  ( -- * Creating a Request
    RestoreFromSnapshot (..),
    newRestoreFromSnapshot,

    -- * Request Lenses
    restoreFromSnapshot_snapshotId,

    -- * Destructuring the Response
    RestoreFromSnapshotResponse (..),
    newRestoreFromSnapshotResponse,

    -- * Response Lenses
    restoreFromSnapshotResponse_httpStatus,
  )
where

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

-- | An object representing the inputs for the RestoreFromSnapshot operation.
--
-- /See:/ 'newRestoreFromSnapshot' smart constructor.
data RestoreFromSnapshot = RestoreFromSnapshot'
  { -- | The identifier of the snapshot to restore from.
    RestoreFromSnapshot -> Text
snapshotId :: Prelude.Text
  }
  deriving (RestoreFromSnapshot -> RestoreFromSnapshot -> Bool
(RestoreFromSnapshot -> RestoreFromSnapshot -> Bool)
-> (RestoreFromSnapshot -> RestoreFromSnapshot -> Bool)
-> Eq RestoreFromSnapshot
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RestoreFromSnapshot -> RestoreFromSnapshot -> Bool
$c/= :: RestoreFromSnapshot -> RestoreFromSnapshot -> Bool
== :: RestoreFromSnapshot -> RestoreFromSnapshot -> Bool
$c== :: RestoreFromSnapshot -> RestoreFromSnapshot -> Bool
Prelude.Eq, ReadPrec [RestoreFromSnapshot]
ReadPrec RestoreFromSnapshot
Int -> ReadS RestoreFromSnapshot
ReadS [RestoreFromSnapshot]
(Int -> ReadS RestoreFromSnapshot)
-> ReadS [RestoreFromSnapshot]
-> ReadPrec RestoreFromSnapshot
-> ReadPrec [RestoreFromSnapshot]
-> Read RestoreFromSnapshot
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RestoreFromSnapshot]
$creadListPrec :: ReadPrec [RestoreFromSnapshot]
readPrec :: ReadPrec RestoreFromSnapshot
$creadPrec :: ReadPrec RestoreFromSnapshot
readList :: ReadS [RestoreFromSnapshot]
$creadList :: ReadS [RestoreFromSnapshot]
readsPrec :: Int -> ReadS RestoreFromSnapshot
$creadsPrec :: Int -> ReadS RestoreFromSnapshot
Prelude.Read, Int -> RestoreFromSnapshot -> ShowS
[RestoreFromSnapshot] -> ShowS
RestoreFromSnapshot -> String
(Int -> RestoreFromSnapshot -> ShowS)
-> (RestoreFromSnapshot -> String)
-> ([RestoreFromSnapshot] -> ShowS)
-> Show RestoreFromSnapshot
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RestoreFromSnapshot] -> ShowS
$cshowList :: [RestoreFromSnapshot] -> ShowS
show :: RestoreFromSnapshot -> String
$cshow :: RestoreFromSnapshot -> String
showsPrec :: Int -> RestoreFromSnapshot -> ShowS
$cshowsPrec :: Int -> RestoreFromSnapshot -> ShowS
Prelude.Show, (forall x. RestoreFromSnapshot -> Rep RestoreFromSnapshot x)
-> (forall x. Rep RestoreFromSnapshot x -> RestoreFromSnapshot)
-> Generic RestoreFromSnapshot
forall x. Rep RestoreFromSnapshot x -> RestoreFromSnapshot
forall x. RestoreFromSnapshot -> Rep RestoreFromSnapshot x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RestoreFromSnapshot x -> RestoreFromSnapshot
$cfrom :: forall x. RestoreFromSnapshot -> Rep RestoreFromSnapshot x
Prelude.Generic)

-- |
-- Create a value of 'RestoreFromSnapshot' 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:
--
-- 'snapshotId', 'restoreFromSnapshot_snapshotId' - The identifier of the snapshot to restore from.
newRestoreFromSnapshot ::
  -- | 'snapshotId'
  Prelude.Text ->
  RestoreFromSnapshot
newRestoreFromSnapshot :: Text -> RestoreFromSnapshot
newRestoreFromSnapshot Text
pSnapshotId_ =
  RestoreFromSnapshot' :: Text -> RestoreFromSnapshot
RestoreFromSnapshot' {$sel:snapshotId:RestoreFromSnapshot' :: Text
snapshotId = Text
pSnapshotId_}

-- | The identifier of the snapshot to restore from.
restoreFromSnapshot_snapshotId :: Lens.Lens' RestoreFromSnapshot Prelude.Text
restoreFromSnapshot_snapshotId :: (Text -> f Text) -> RestoreFromSnapshot -> f RestoreFromSnapshot
restoreFromSnapshot_snapshotId = (RestoreFromSnapshot -> Text)
-> (RestoreFromSnapshot -> Text -> RestoreFromSnapshot)
-> Lens RestoreFromSnapshot RestoreFromSnapshot Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RestoreFromSnapshot' {Text
snapshotId :: Text
$sel:snapshotId:RestoreFromSnapshot' :: RestoreFromSnapshot -> Text
snapshotId} -> Text
snapshotId) (\s :: RestoreFromSnapshot
s@RestoreFromSnapshot' {} Text
a -> RestoreFromSnapshot
s {$sel:snapshotId:RestoreFromSnapshot' :: Text
snapshotId = Text
a} :: RestoreFromSnapshot)

instance Core.AWSRequest RestoreFromSnapshot where
  type
    AWSResponse RestoreFromSnapshot =
      RestoreFromSnapshotResponse
  request :: RestoreFromSnapshot -> Request RestoreFromSnapshot
request = Service -> RestoreFromSnapshot -> Request RestoreFromSnapshot
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy RestoreFromSnapshot
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse RestoreFromSnapshot)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse RestoreFromSnapshot))
-> Logger
-> Service
-> Proxy RestoreFromSnapshot
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse RestoreFromSnapshot)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> RestoreFromSnapshotResponse
RestoreFromSnapshotResponse'
            (Int -> RestoreFromSnapshotResponse)
-> Either String Int -> Either String RestoreFromSnapshotResponse
forall (f :: * -> *) a b. Functor 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 RestoreFromSnapshot

instance Prelude.NFData RestoreFromSnapshot

instance Core.ToHeaders RestoreFromSnapshot where
  toHeaders :: RestoreFromSnapshot -> ResponseHeaders
toHeaders =
    ResponseHeaders -> RestoreFromSnapshot -> 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
"DirectoryService_20150416.RestoreFromSnapshot" ::
                          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 RestoreFromSnapshot where
  toJSON :: RestoreFromSnapshot -> Value
toJSON RestoreFromSnapshot' {Text
snapshotId :: Text
$sel:snapshotId:RestoreFromSnapshot' :: RestoreFromSnapshot -> 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
"SnapshotId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
snapshotId)]
      )

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

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

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

-- |
-- Create a value of 'RestoreFromSnapshotResponse' 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:
--
-- 'httpStatus', 'restoreFromSnapshotResponse_httpStatus' - The response's http status code.
newRestoreFromSnapshotResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  RestoreFromSnapshotResponse
newRestoreFromSnapshotResponse :: Int -> RestoreFromSnapshotResponse
newRestoreFromSnapshotResponse Int
pHttpStatus_ =
  RestoreFromSnapshotResponse' :: Int -> RestoreFromSnapshotResponse
RestoreFromSnapshotResponse'
    { $sel:httpStatus:RestoreFromSnapshotResponse' :: Int
httpStatus =
        Int
pHttpStatus_
    }

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

instance Prelude.NFData RestoreFromSnapshotResponse