{-# 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.StartWorkspaces
-- 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)
--
-- Starts the specified WorkSpaces.
--
-- You cannot start a WorkSpace unless it has a running mode of @AutoStop@
-- and a state of @STOPPED@.
module Amazonka.WorkSpaces.StartWorkspaces
  ( -- * Creating a Request
    StartWorkspaces (..),
    newStartWorkspaces,

    -- * Request Lenses
    startWorkspaces_startWorkspaceRequests,

    -- * Destructuring the Response
    StartWorkspacesResponse (..),
    newStartWorkspacesResponse,

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

-- |
-- Create a value of 'StartWorkspaces' 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:
--
-- 'startWorkspaceRequests', 'startWorkspaces_startWorkspaceRequests' - The WorkSpaces to start. You can specify up to 25 WorkSpaces.
newStartWorkspaces ::
  -- | 'startWorkspaceRequests'
  Prelude.NonEmpty StartRequest ->
  StartWorkspaces
newStartWorkspaces :: NonEmpty StartRequest -> StartWorkspaces
newStartWorkspaces NonEmpty StartRequest
pStartWorkspaceRequests_ =
  StartWorkspaces' :: NonEmpty StartRequest -> StartWorkspaces
StartWorkspaces'
    { $sel:startWorkspaceRequests:StartWorkspaces' :: NonEmpty StartRequest
startWorkspaceRequests =
        Tagged (NonEmpty StartRequest) (Identity (NonEmpty StartRequest))
-> Tagged
     (NonEmpty StartRequest) (Identity (NonEmpty StartRequest))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged (NonEmpty StartRequest) (Identity (NonEmpty StartRequest))
 -> Tagged
      (NonEmpty StartRequest) (Identity (NonEmpty StartRequest)))
-> NonEmpty StartRequest -> NonEmpty StartRequest
forall t b. AReview t b -> b -> t
Lens.# NonEmpty StartRequest
pStartWorkspaceRequests_
    }

-- | The WorkSpaces to start. You can specify up to 25 WorkSpaces.
startWorkspaces_startWorkspaceRequests :: Lens.Lens' StartWorkspaces (Prelude.NonEmpty StartRequest)
startWorkspaces_startWorkspaceRequests :: (NonEmpty StartRequest -> f (NonEmpty StartRequest))
-> StartWorkspaces -> f StartWorkspaces
startWorkspaces_startWorkspaceRequests = (StartWorkspaces -> NonEmpty StartRequest)
-> (StartWorkspaces -> NonEmpty StartRequest -> StartWorkspaces)
-> Lens
     StartWorkspaces
     StartWorkspaces
     (NonEmpty StartRequest)
     (NonEmpty StartRequest)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartWorkspaces' {NonEmpty StartRequest
startWorkspaceRequests :: NonEmpty StartRequest
$sel:startWorkspaceRequests:StartWorkspaces' :: StartWorkspaces -> NonEmpty StartRequest
startWorkspaceRequests} -> NonEmpty StartRequest
startWorkspaceRequests) (\s :: StartWorkspaces
s@StartWorkspaces' {} NonEmpty StartRequest
a -> StartWorkspaces
s {$sel:startWorkspaceRequests:StartWorkspaces' :: NonEmpty StartRequest
startWorkspaceRequests = NonEmpty StartRequest
a} :: StartWorkspaces) ((NonEmpty StartRequest -> f (NonEmpty StartRequest))
 -> StartWorkspaces -> f StartWorkspaces)
-> ((NonEmpty StartRequest -> f (NonEmpty StartRequest))
    -> NonEmpty StartRequest -> f (NonEmpty StartRequest))
-> (NonEmpty StartRequest -> f (NonEmpty StartRequest))
-> StartWorkspaces
-> f StartWorkspaces
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty StartRequest -> f (NonEmpty StartRequest))
-> NonEmpty StartRequest -> f (NonEmpty StartRequest)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData StartWorkspaces

instance Core.ToHeaders StartWorkspaces where
  toHeaders :: StartWorkspaces -> ResponseHeaders
toHeaders =
    ResponseHeaders -> StartWorkspaces -> 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.StartWorkspaces" ::
                          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 StartWorkspaces where
  toJSON :: StartWorkspaces -> Value
toJSON StartWorkspaces' {NonEmpty StartRequest
startWorkspaceRequests :: NonEmpty StartRequest
$sel:startWorkspaceRequests:StartWorkspaces' :: StartWorkspaces -> NonEmpty StartRequest
..} =
    [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
"StartWorkspaceRequests"
                  Key -> NonEmpty StartRequest -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Core..= NonEmpty StartRequest
startWorkspaceRequests
              )
          ]
      )

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

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

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

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

-- | Information about the WorkSpaces that could not be started.
startWorkspacesResponse_failedRequests :: Lens.Lens' StartWorkspacesResponse (Prelude.Maybe [FailedWorkspaceChangeRequest])
startWorkspacesResponse_failedRequests :: (Maybe [FailedWorkspaceChangeRequest]
 -> f (Maybe [FailedWorkspaceChangeRequest]))
-> StartWorkspacesResponse -> f StartWorkspacesResponse
startWorkspacesResponse_failedRequests = (StartWorkspacesResponse -> Maybe [FailedWorkspaceChangeRequest])
-> (StartWorkspacesResponse
    -> Maybe [FailedWorkspaceChangeRequest] -> StartWorkspacesResponse)
-> Lens
     StartWorkspacesResponse
     StartWorkspacesResponse
     (Maybe [FailedWorkspaceChangeRequest])
     (Maybe [FailedWorkspaceChangeRequest])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartWorkspacesResponse' {Maybe [FailedWorkspaceChangeRequest]
failedRequests :: Maybe [FailedWorkspaceChangeRequest]
$sel:failedRequests:StartWorkspacesResponse' :: StartWorkspacesResponse -> Maybe [FailedWorkspaceChangeRequest]
failedRequests} -> Maybe [FailedWorkspaceChangeRequest]
failedRequests) (\s :: StartWorkspacesResponse
s@StartWorkspacesResponse' {} Maybe [FailedWorkspaceChangeRequest]
a -> StartWorkspacesResponse
s {$sel:failedRequests:StartWorkspacesResponse' :: Maybe [FailedWorkspaceChangeRequest]
failedRequests = Maybe [FailedWorkspaceChangeRequest]
a} :: StartWorkspacesResponse) ((Maybe [FailedWorkspaceChangeRequest]
  -> f (Maybe [FailedWorkspaceChangeRequest]))
 -> StartWorkspacesResponse -> f StartWorkspacesResponse)
-> ((Maybe [FailedWorkspaceChangeRequest]
     -> f (Maybe [FailedWorkspaceChangeRequest]))
    -> Maybe [FailedWorkspaceChangeRequest]
    -> f (Maybe [FailedWorkspaceChangeRequest]))
-> (Maybe [FailedWorkspaceChangeRequest]
    -> f (Maybe [FailedWorkspaceChangeRequest]))
-> StartWorkspacesResponse
-> f StartWorkspacesResponse
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.
startWorkspacesResponse_httpStatus :: Lens.Lens' StartWorkspacesResponse Prelude.Int
startWorkspacesResponse_httpStatus :: (Int -> f Int)
-> StartWorkspacesResponse -> f StartWorkspacesResponse
startWorkspacesResponse_httpStatus = (StartWorkspacesResponse -> Int)
-> (StartWorkspacesResponse -> Int -> StartWorkspacesResponse)
-> Lens StartWorkspacesResponse StartWorkspacesResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartWorkspacesResponse' {Int
httpStatus :: Int
$sel:httpStatus:StartWorkspacesResponse' :: StartWorkspacesResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: StartWorkspacesResponse
s@StartWorkspacesResponse' {} Int
a -> StartWorkspacesResponse
s {$sel:httpStatus:StartWorkspacesResponse' :: Int
httpStatus = Int
a} :: StartWorkspacesResponse)

instance Prelude.NFData StartWorkspacesResponse