{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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 qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.DirectoryService.Types
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
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]
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
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. 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' {$sel:snapshotId:RestoreFromSnapshot' :: Text
snapshotId = Text
pSnapshotId_}

-- | The identifier of the snapshot to restore from.
restoreFromSnapshot_snapshotId :: Lens.Lens' RestoreFromSnapshot Prelude.Text
restoreFromSnapshot_snapshotId :: Lens' RestoreFromSnapshot Text
restoreFromSnapshot_snapshotId = 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 :: (Service -> Service)
-> RestoreFromSnapshot -> Request RestoreFromSnapshot
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 RestoreFromSnapshot
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse RestoreFromSnapshot)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> RestoreFromSnapshotResponse
RestoreFromSnapshotResponse'
            forall (f :: * -> *) a b. Functor 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 RestoreFromSnapshot where
  hashWithSalt :: Int -> RestoreFromSnapshot -> Int
hashWithSalt Int
_salt RestoreFromSnapshot' {Text
snapshotId :: Text
$sel:snapshotId:RestoreFromSnapshot' :: RestoreFromSnapshot -> Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
snapshotId

instance Prelude.NFData RestoreFromSnapshot where
  rnf :: RestoreFromSnapshot -> ()
rnf RestoreFromSnapshot' {Text
snapshotId :: Text
$sel:snapshotId:RestoreFromSnapshot' :: RestoreFromSnapshot -> Text
..} = forall a. NFData a => a -> ()
Prelude.rnf Text
snapshotId

instance Data.ToHeaders RestoreFromSnapshot where
  toHeaders :: RestoreFromSnapshot -> 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
"DirectoryService_20150416.RestoreFromSnapshot" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

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

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

instance Data.ToQuery RestoreFromSnapshot where
  toQuery :: RestoreFromSnapshot -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const 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
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]
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
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.
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'
    { $sel:httpStatus:RestoreFromSnapshotResponse' :: Int
httpStatus =
        Int
pHttpStatus_
    }

-- | The response's http status code.
restoreFromSnapshotResponse_httpStatus :: Lens.Lens' RestoreFromSnapshotResponse Prelude.Int
restoreFromSnapshotResponse_httpStatus :: Lens' RestoreFromSnapshotResponse Int
restoreFromSnapshotResponse_httpStatus = 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 where
  rnf :: RestoreFromSnapshotResponse -> ()
rnf RestoreFromSnapshotResponse' {Int
httpStatus :: Int
$sel:httpStatus:RestoreFromSnapshotResponse' :: RestoreFromSnapshotResponse -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus