{-# 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.StopWorkspaces
-- 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)
--
-- Stops the specified WorkSpaces.
--
-- You cannot stop a WorkSpace unless it has a running mode of @AutoStop@
-- and a state of @AVAILABLE@, @IMPAIRED@, @UNHEALTHY@, or @ERROR@.
module Amazonka.WorkSpaces.StopWorkspaces
  ( -- * Creating a Request
    StopWorkspaces (..),
    newStopWorkspaces,

    -- * Request Lenses
    stopWorkspaces_stopWorkspaceRequests,

    -- * Destructuring the Response
    StopWorkspacesResponse (..),
    newStopWorkspacesResponse,

    -- * Response Lenses
    stopWorkspacesResponse_failedRequests,
    stopWorkspacesResponse_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:/ 'newStopWorkspaces' smart constructor.
data StopWorkspaces = StopWorkspaces'
  { -- | The WorkSpaces to stop. You can specify up to 25 WorkSpaces.
    StopWorkspaces -> NonEmpty StopRequest
stopWorkspaceRequests :: Prelude.NonEmpty StopRequest
  }
  deriving (StopWorkspaces -> StopWorkspaces -> Bool
(StopWorkspaces -> StopWorkspaces -> Bool)
-> (StopWorkspaces -> StopWorkspaces -> Bool) -> Eq StopWorkspaces
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StopWorkspaces -> StopWorkspaces -> Bool
$c/= :: StopWorkspaces -> StopWorkspaces -> Bool
== :: StopWorkspaces -> StopWorkspaces -> Bool
$c== :: StopWorkspaces -> StopWorkspaces -> Bool
Prelude.Eq, ReadPrec [StopWorkspaces]
ReadPrec StopWorkspaces
Int -> ReadS StopWorkspaces
ReadS [StopWorkspaces]
(Int -> ReadS StopWorkspaces)
-> ReadS [StopWorkspaces]
-> ReadPrec StopWorkspaces
-> ReadPrec [StopWorkspaces]
-> Read StopWorkspaces
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StopWorkspaces]
$creadListPrec :: ReadPrec [StopWorkspaces]
readPrec :: ReadPrec StopWorkspaces
$creadPrec :: ReadPrec StopWorkspaces
readList :: ReadS [StopWorkspaces]
$creadList :: ReadS [StopWorkspaces]
readsPrec :: Int -> ReadS StopWorkspaces
$creadsPrec :: Int -> ReadS StopWorkspaces
Prelude.Read, Int -> StopWorkspaces -> ShowS
[StopWorkspaces] -> ShowS
StopWorkspaces -> String
(Int -> StopWorkspaces -> ShowS)
-> (StopWorkspaces -> String)
-> ([StopWorkspaces] -> ShowS)
-> Show StopWorkspaces
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StopWorkspaces] -> ShowS
$cshowList :: [StopWorkspaces] -> ShowS
show :: StopWorkspaces -> String
$cshow :: StopWorkspaces -> String
showsPrec :: Int -> StopWorkspaces -> ShowS
$cshowsPrec :: Int -> StopWorkspaces -> ShowS
Prelude.Show, (forall x. StopWorkspaces -> Rep StopWorkspaces x)
-> (forall x. Rep StopWorkspaces x -> StopWorkspaces)
-> Generic StopWorkspaces
forall x. Rep StopWorkspaces x -> StopWorkspaces
forall x. StopWorkspaces -> Rep StopWorkspaces x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StopWorkspaces x -> StopWorkspaces
$cfrom :: forall x. StopWorkspaces -> Rep StopWorkspaces x
Prelude.Generic)

-- |
-- Create a value of 'StopWorkspaces' 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:
--
-- 'stopWorkspaceRequests', 'stopWorkspaces_stopWorkspaceRequests' - The WorkSpaces to stop. You can specify up to 25 WorkSpaces.
newStopWorkspaces ::
  -- | 'stopWorkspaceRequests'
  Prelude.NonEmpty StopRequest ->
  StopWorkspaces
newStopWorkspaces :: NonEmpty StopRequest -> StopWorkspaces
newStopWorkspaces NonEmpty StopRequest
pStopWorkspaceRequests_ =
  StopWorkspaces' :: NonEmpty StopRequest -> StopWorkspaces
StopWorkspaces'
    { $sel:stopWorkspaceRequests:StopWorkspaces' :: NonEmpty StopRequest
stopWorkspaceRequests =
        Tagged (NonEmpty StopRequest) (Identity (NonEmpty StopRequest))
-> Tagged (NonEmpty StopRequest) (Identity (NonEmpty StopRequest))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged (NonEmpty StopRequest) (Identity (NonEmpty StopRequest))
 -> Tagged (NonEmpty StopRequest) (Identity (NonEmpty StopRequest)))
-> NonEmpty StopRequest -> NonEmpty StopRequest
forall t b. AReview t b -> b -> t
Lens.# NonEmpty StopRequest
pStopWorkspaceRequests_
    }

-- | The WorkSpaces to stop. You can specify up to 25 WorkSpaces.
stopWorkspaces_stopWorkspaceRequests :: Lens.Lens' StopWorkspaces (Prelude.NonEmpty StopRequest)
stopWorkspaces_stopWorkspaceRequests :: (NonEmpty StopRequest -> f (NonEmpty StopRequest))
-> StopWorkspaces -> f StopWorkspaces
stopWorkspaces_stopWorkspaceRequests = (StopWorkspaces -> NonEmpty StopRequest)
-> (StopWorkspaces -> NonEmpty StopRequest -> StopWorkspaces)
-> Lens
     StopWorkspaces
     StopWorkspaces
     (NonEmpty StopRequest)
     (NonEmpty StopRequest)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StopWorkspaces' {NonEmpty StopRequest
stopWorkspaceRequests :: NonEmpty StopRequest
$sel:stopWorkspaceRequests:StopWorkspaces' :: StopWorkspaces -> NonEmpty StopRequest
stopWorkspaceRequests} -> NonEmpty StopRequest
stopWorkspaceRequests) (\s :: StopWorkspaces
s@StopWorkspaces' {} NonEmpty StopRequest
a -> StopWorkspaces
s {$sel:stopWorkspaceRequests:StopWorkspaces' :: NonEmpty StopRequest
stopWorkspaceRequests = NonEmpty StopRequest
a} :: StopWorkspaces) ((NonEmpty StopRequest -> f (NonEmpty StopRequest))
 -> StopWorkspaces -> f StopWorkspaces)
-> ((NonEmpty StopRequest -> f (NonEmpty StopRequest))
    -> NonEmpty StopRequest -> f (NonEmpty StopRequest))
-> (NonEmpty StopRequest -> f (NonEmpty StopRequest))
-> StopWorkspaces
-> f StopWorkspaces
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty StopRequest -> f (NonEmpty StopRequest))
-> NonEmpty StopRequest -> f (NonEmpty StopRequest)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest StopWorkspaces where
  type
    AWSResponse StopWorkspaces =
      StopWorkspacesResponse
  request :: StopWorkspaces -> Request StopWorkspaces
request = Service -> StopWorkspaces -> Request StopWorkspaces
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy StopWorkspaces
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse StopWorkspaces)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse StopWorkspaces))
-> Logger
-> Service
-> Proxy StopWorkspaces
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse StopWorkspaces)))
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 [FailedWorkspaceChangeRequest]
-> Int -> StopWorkspacesResponse
StopWorkspacesResponse'
            (Maybe [FailedWorkspaceChangeRequest]
 -> Int -> StopWorkspacesResponse)
-> Either String (Maybe [FailedWorkspaceChangeRequest])
-> Either String (Int -> StopWorkspacesResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object
-> Key
-> Either String (Maybe (Maybe [FailedWorkspaceChangeRequest]))
forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Core..?> Key
"FailedRequests" Either String (Maybe (Maybe [FailedWorkspaceChangeRequest]))
-> Maybe [FailedWorkspaceChangeRequest]
-> Either String (Maybe [FailedWorkspaceChangeRequest])
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ Maybe [FailedWorkspaceChangeRequest]
forall a. Monoid a => a
Prelude.mempty)
            Either String (Int -> StopWorkspacesResponse)
-> Either String Int -> Either String StopWorkspacesResponse
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 StopWorkspaces

instance Prelude.NFData StopWorkspaces

instance Core.ToHeaders StopWorkspaces where
  toHeaders :: StopWorkspaces -> ResponseHeaders
toHeaders =
    ResponseHeaders -> StopWorkspaces -> 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.StopWorkspaces" ::
                          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 StopWorkspaces where
  toJSON :: StopWorkspaces -> Value
toJSON StopWorkspaces' {NonEmpty StopRequest
stopWorkspaceRequests :: NonEmpty StopRequest
$sel:stopWorkspaceRequests:StopWorkspaces' :: StopWorkspaces -> NonEmpty StopRequest
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              ( Key
"StopWorkspaceRequests"
                  Key -> NonEmpty StopRequest -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Core..= NonEmpty StopRequest
stopWorkspaceRequests
              )
          ]
      )

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

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

-- | /See:/ 'newStopWorkspacesResponse' smart constructor.
data StopWorkspacesResponse = StopWorkspacesResponse'
  { -- | Information about the WorkSpaces that could not be stopped.
    StopWorkspacesResponse -> Maybe [FailedWorkspaceChangeRequest]
failedRequests :: Prelude.Maybe [FailedWorkspaceChangeRequest],
    -- | The response's http status code.
    StopWorkspacesResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (StopWorkspacesResponse -> StopWorkspacesResponse -> Bool
(StopWorkspacesResponse -> StopWorkspacesResponse -> Bool)
-> (StopWorkspacesResponse -> StopWorkspacesResponse -> Bool)
-> Eq StopWorkspacesResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StopWorkspacesResponse -> StopWorkspacesResponse -> Bool
$c/= :: StopWorkspacesResponse -> StopWorkspacesResponse -> Bool
== :: StopWorkspacesResponse -> StopWorkspacesResponse -> Bool
$c== :: StopWorkspacesResponse -> StopWorkspacesResponse -> Bool
Prelude.Eq, ReadPrec [StopWorkspacesResponse]
ReadPrec StopWorkspacesResponse
Int -> ReadS StopWorkspacesResponse
ReadS [StopWorkspacesResponse]
(Int -> ReadS StopWorkspacesResponse)
-> ReadS [StopWorkspacesResponse]
-> ReadPrec StopWorkspacesResponse
-> ReadPrec [StopWorkspacesResponse]
-> Read StopWorkspacesResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StopWorkspacesResponse]
$creadListPrec :: ReadPrec [StopWorkspacesResponse]
readPrec :: ReadPrec StopWorkspacesResponse
$creadPrec :: ReadPrec StopWorkspacesResponse
readList :: ReadS [StopWorkspacesResponse]
$creadList :: ReadS [StopWorkspacesResponse]
readsPrec :: Int -> ReadS StopWorkspacesResponse
$creadsPrec :: Int -> ReadS StopWorkspacesResponse
Prelude.Read, Int -> StopWorkspacesResponse -> ShowS
[StopWorkspacesResponse] -> ShowS
StopWorkspacesResponse -> String
(Int -> StopWorkspacesResponse -> ShowS)
-> (StopWorkspacesResponse -> String)
-> ([StopWorkspacesResponse] -> ShowS)
-> Show StopWorkspacesResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StopWorkspacesResponse] -> ShowS
$cshowList :: [StopWorkspacesResponse] -> ShowS
show :: StopWorkspacesResponse -> String
$cshow :: StopWorkspacesResponse -> String
showsPrec :: Int -> StopWorkspacesResponse -> ShowS
$cshowsPrec :: Int -> StopWorkspacesResponse -> ShowS
Prelude.Show, (forall x. StopWorkspacesResponse -> Rep StopWorkspacesResponse x)
-> (forall x.
    Rep StopWorkspacesResponse x -> StopWorkspacesResponse)
-> Generic StopWorkspacesResponse
forall x. Rep StopWorkspacesResponse x -> StopWorkspacesResponse
forall x. StopWorkspacesResponse -> Rep StopWorkspacesResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StopWorkspacesResponse x -> StopWorkspacesResponse
$cfrom :: forall x. StopWorkspacesResponse -> Rep StopWorkspacesResponse x
Prelude.Generic)

-- |
-- Create a value of 'StopWorkspacesResponse' 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:
--
-- 'failedRequests', 'stopWorkspacesResponse_failedRequests' - Information about the WorkSpaces that could not be stopped.
--
-- 'httpStatus', 'stopWorkspacesResponse_httpStatus' - The response's http status code.
newStopWorkspacesResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  StopWorkspacesResponse
newStopWorkspacesResponse :: Int -> StopWorkspacesResponse
newStopWorkspacesResponse Int
pHttpStatus_ =
  StopWorkspacesResponse' :: Maybe [FailedWorkspaceChangeRequest]
-> Int -> StopWorkspacesResponse
StopWorkspacesResponse'
    { $sel:failedRequests:StopWorkspacesResponse' :: Maybe [FailedWorkspaceChangeRequest]
failedRequests =
        Maybe [FailedWorkspaceChangeRequest]
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:StopWorkspacesResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Information about the WorkSpaces that could not be stopped.
stopWorkspacesResponse_failedRequests :: Lens.Lens' StopWorkspacesResponse (Prelude.Maybe [FailedWorkspaceChangeRequest])
stopWorkspacesResponse_failedRequests :: (Maybe [FailedWorkspaceChangeRequest]
 -> f (Maybe [FailedWorkspaceChangeRequest]))
-> StopWorkspacesResponse -> f StopWorkspacesResponse
stopWorkspacesResponse_failedRequests = (StopWorkspacesResponse -> Maybe [FailedWorkspaceChangeRequest])
-> (StopWorkspacesResponse
    -> Maybe [FailedWorkspaceChangeRequest] -> StopWorkspacesResponse)
-> Lens
     StopWorkspacesResponse
     StopWorkspacesResponse
     (Maybe [FailedWorkspaceChangeRequest])
     (Maybe [FailedWorkspaceChangeRequest])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StopWorkspacesResponse' {Maybe [FailedWorkspaceChangeRequest]
failedRequests :: Maybe [FailedWorkspaceChangeRequest]
$sel:failedRequests:StopWorkspacesResponse' :: StopWorkspacesResponse -> Maybe [FailedWorkspaceChangeRequest]
failedRequests} -> Maybe [FailedWorkspaceChangeRequest]
failedRequests) (\s :: StopWorkspacesResponse
s@StopWorkspacesResponse' {} Maybe [FailedWorkspaceChangeRequest]
a -> StopWorkspacesResponse
s {$sel:failedRequests:StopWorkspacesResponse' :: Maybe [FailedWorkspaceChangeRequest]
failedRequests = Maybe [FailedWorkspaceChangeRequest]
a} :: StopWorkspacesResponse) ((Maybe [FailedWorkspaceChangeRequest]
  -> f (Maybe [FailedWorkspaceChangeRequest]))
 -> StopWorkspacesResponse -> f StopWorkspacesResponse)
-> ((Maybe [FailedWorkspaceChangeRequest]
     -> f (Maybe [FailedWorkspaceChangeRequest]))
    -> Maybe [FailedWorkspaceChangeRequest]
    -> f (Maybe [FailedWorkspaceChangeRequest]))
-> (Maybe [FailedWorkspaceChangeRequest]
    -> f (Maybe [FailedWorkspaceChangeRequest]))
-> StopWorkspacesResponse
-> f StopWorkspacesResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [FailedWorkspaceChangeRequest]
  [FailedWorkspaceChangeRequest]
  [FailedWorkspaceChangeRequest]
  [FailedWorkspaceChangeRequest]
-> Iso
     (Maybe [FailedWorkspaceChangeRequest])
     (Maybe [FailedWorkspaceChangeRequest])
     (Maybe [FailedWorkspaceChangeRequest])
     (Maybe [FailedWorkspaceChangeRequest])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  [FailedWorkspaceChangeRequest]
  [FailedWorkspaceChangeRequest]
  [FailedWorkspaceChangeRequest]
  [FailedWorkspaceChangeRequest]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData StopWorkspacesResponse