{-# 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.WorkSpaces.RestoreWorkspace
-- 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 the specified WorkSpace to its last known healthy state.
--
-- You cannot restore a WorkSpace unless its state is @ AVAILABLE@,
-- @ERROR@, @UNHEALTHY@, or @STOPPED@.
--
-- Restoring a WorkSpace is a potentially destructive action that can
-- result in the loss of data. For more information, see
-- <https://docs.aws.amazon.com/workspaces/latest/adminguide/restore-workspace.html Restore a WorkSpace>.
--
-- This operation is asynchronous and returns before the WorkSpace is
-- completely restored.
module Amazonka.WorkSpaces.RestoreWorkspace
  ( -- * Creating a Request
    RestoreWorkspace (..),
    newRestoreWorkspace,

    -- * Request Lenses
    restoreWorkspace_workspaceId,

    -- * Destructuring the Response
    RestoreWorkspaceResponse (..),
    newRestoreWorkspaceResponse,

    -- * Response Lenses
    restoreWorkspaceResponse_httpStatus,
  )
where

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
import Amazonka.WorkSpaces.Types

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

-- |
-- Create a value of 'RestoreWorkspace' 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:
--
-- 'workspaceId', 'restoreWorkspace_workspaceId' - The identifier of the WorkSpace.
newRestoreWorkspace ::
  -- | 'workspaceId'
  Prelude.Text ->
  RestoreWorkspace
newRestoreWorkspace :: Text -> RestoreWorkspace
newRestoreWorkspace Text
pWorkspaceId_ =
  RestoreWorkspace' :: Text -> RestoreWorkspace
RestoreWorkspace' {$sel:workspaceId:RestoreWorkspace' :: Text
workspaceId = Text
pWorkspaceId_}

-- | The identifier of the WorkSpace.
restoreWorkspace_workspaceId :: Lens.Lens' RestoreWorkspace Prelude.Text
restoreWorkspace_workspaceId :: (Text -> f Text) -> RestoreWorkspace -> f RestoreWorkspace
restoreWorkspace_workspaceId = (RestoreWorkspace -> Text)
-> (RestoreWorkspace -> Text -> RestoreWorkspace)
-> Lens RestoreWorkspace RestoreWorkspace Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RestoreWorkspace' {Text
workspaceId :: Text
$sel:workspaceId:RestoreWorkspace' :: RestoreWorkspace -> Text
workspaceId} -> Text
workspaceId) (\s :: RestoreWorkspace
s@RestoreWorkspace' {} Text
a -> RestoreWorkspace
s {$sel:workspaceId:RestoreWorkspace' :: Text
workspaceId = Text
a} :: RestoreWorkspace)

instance Core.AWSRequest RestoreWorkspace where
  type
    AWSResponse RestoreWorkspace =
      RestoreWorkspaceResponse
  request :: RestoreWorkspace -> Request RestoreWorkspace
request = Service -> RestoreWorkspace -> Request RestoreWorkspace
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy RestoreWorkspace
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse RestoreWorkspace)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse RestoreWorkspace))
-> Logger
-> Service
-> Proxy RestoreWorkspace
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse RestoreWorkspace)))
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 -> RestoreWorkspaceResponse
RestoreWorkspaceResponse'
            (Int -> RestoreWorkspaceResponse)
-> Either String Int -> Either String RestoreWorkspaceResponse
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 RestoreWorkspace

instance Prelude.NFData RestoreWorkspace

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

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

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

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

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

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

instance Prelude.NFData RestoreWorkspaceResponse