{-# 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.AppStream.BatchAssociateUserStack
-- 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)
--
-- Associates the specified users with the specified stacks. Users in a
-- user pool cannot be assigned to stacks with fleets that are joined to an
-- Active Directory domain.
module Amazonka.AppStream.BatchAssociateUserStack
  ( -- * Creating a Request
    BatchAssociateUserStack (..),
    newBatchAssociateUserStack,

    -- * Request Lenses
    batchAssociateUserStack_userStackAssociations,

    -- * Destructuring the Response
    BatchAssociateUserStackResponse (..),
    newBatchAssociateUserStackResponse,

    -- * Response Lenses
    batchAssociateUserStackResponse_errors,
    batchAssociateUserStackResponse_httpStatus,
  )
where

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

-- | /See:/ 'newBatchAssociateUserStack' smart constructor.
data BatchAssociateUserStack = BatchAssociateUserStack'
  { -- | The list of UserStackAssociation objects.
    BatchAssociateUserStack -> NonEmpty UserStackAssociation
userStackAssociations :: Prelude.NonEmpty UserStackAssociation
  }
  deriving (BatchAssociateUserStack -> BatchAssociateUserStack -> Bool
(BatchAssociateUserStack -> BatchAssociateUserStack -> Bool)
-> (BatchAssociateUserStack -> BatchAssociateUserStack -> Bool)
-> Eq BatchAssociateUserStack
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BatchAssociateUserStack -> BatchAssociateUserStack -> Bool
$c/= :: BatchAssociateUserStack -> BatchAssociateUserStack -> Bool
== :: BatchAssociateUserStack -> BatchAssociateUserStack -> Bool
$c== :: BatchAssociateUserStack -> BatchAssociateUserStack -> Bool
Prelude.Eq, Int -> BatchAssociateUserStack -> ShowS
[BatchAssociateUserStack] -> ShowS
BatchAssociateUserStack -> String
(Int -> BatchAssociateUserStack -> ShowS)
-> (BatchAssociateUserStack -> String)
-> ([BatchAssociateUserStack] -> ShowS)
-> Show BatchAssociateUserStack
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BatchAssociateUserStack] -> ShowS
$cshowList :: [BatchAssociateUserStack] -> ShowS
show :: BatchAssociateUserStack -> String
$cshow :: BatchAssociateUserStack -> String
showsPrec :: Int -> BatchAssociateUserStack -> ShowS
$cshowsPrec :: Int -> BatchAssociateUserStack -> ShowS
Prelude.Show, (forall x.
 BatchAssociateUserStack -> Rep BatchAssociateUserStack x)
-> (forall x.
    Rep BatchAssociateUserStack x -> BatchAssociateUserStack)
-> Generic BatchAssociateUserStack
forall x. Rep BatchAssociateUserStack x -> BatchAssociateUserStack
forall x. BatchAssociateUserStack -> Rep BatchAssociateUserStack x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BatchAssociateUserStack x -> BatchAssociateUserStack
$cfrom :: forall x. BatchAssociateUserStack -> Rep BatchAssociateUserStack x
Prelude.Generic)

-- |
-- Create a value of 'BatchAssociateUserStack' 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:
--
-- 'userStackAssociations', 'batchAssociateUserStack_userStackAssociations' - The list of UserStackAssociation objects.
newBatchAssociateUserStack ::
  -- | 'userStackAssociations'
  Prelude.NonEmpty UserStackAssociation ->
  BatchAssociateUserStack
newBatchAssociateUserStack :: NonEmpty UserStackAssociation -> BatchAssociateUserStack
newBatchAssociateUserStack NonEmpty UserStackAssociation
pUserStackAssociations_ =
  BatchAssociateUserStack' :: NonEmpty UserStackAssociation -> BatchAssociateUserStack
BatchAssociateUserStack'
    { $sel:userStackAssociations:BatchAssociateUserStack' :: NonEmpty UserStackAssociation
userStackAssociations =
        Tagged
  (NonEmpty UserStackAssociation)
  (Identity (NonEmpty UserStackAssociation))
-> Tagged
     (NonEmpty UserStackAssociation)
     (Identity (NonEmpty UserStackAssociation))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged
   (NonEmpty UserStackAssociation)
   (Identity (NonEmpty UserStackAssociation))
 -> Tagged
      (NonEmpty UserStackAssociation)
      (Identity (NonEmpty UserStackAssociation)))
-> NonEmpty UserStackAssociation -> NonEmpty UserStackAssociation
forall t b. AReview t b -> b -> t
Lens.# NonEmpty UserStackAssociation
pUserStackAssociations_
    }

-- | The list of UserStackAssociation objects.
batchAssociateUserStack_userStackAssociations :: Lens.Lens' BatchAssociateUserStack (Prelude.NonEmpty UserStackAssociation)
batchAssociateUserStack_userStackAssociations :: (NonEmpty UserStackAssociation
 -> f (NonEmpty UserStackAssociation))
-> BatchAssociateUserStack -> f BatchAssociateUserStack
batchAssociateUserStack_userStackAssociations = (BatchAssociateUserStack -> NonEmpty UserStackAssociation)
-> (BatchAssociateUserStack
    -> NonEmpty UserStackAssociation -> BatchAssociateUserStack)
-> Lens
     BatchAssociateUserStack
     BatchAssociateUserStack
     (NonEmpty UserStackAssociation)
     (NonEmpty UserStackAssociation)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchAssociateUserStack' {NonEmpty UserStackAssociation
userStackAssociations :: NonEmpty UserStackAssociation
$sel:userStackAssociations:BatchAssociateUserStack' :: BatchAssociateUserStack -> NonEmpty UserStackAssociation
userStackAssociations} -> NonEmpty UserStackAssociation
userStackAssociations) (\s :: BatchAssociateUserStack
s@BatchAssociateUserStack' {} NonEmpty UserStackAssociation
a -> BatchAssociateUserStack
s {$sel:userStackAssociations:BatchAssociateUserStack' :: NonEmpty UserStackAssociation
userStackAssociations = NonEmpty UserStackAssociation
a} :: BatchAssociateUserStack) ((NonEmpty UserStackAssociation
  -> f (NonEmpty UserStackAssociation))
 -> BatchAssociateUserStack -> f BatchAssociateUserStack)
-> ((NonEmpty UserStackAssociation
     -> f (NonEmpty UserStackAssociation))
    -> NonEmpty UserStackAssociation
    -> f (NonEmpty UserStackAssociation))
-> (NonEmpty UserStackAssociation
    -> f (NonEmpty UserStackAssociation))
-> BatchAssociateUserStack
-> f BatchAssociateUserStack
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty UserStackAssociation
 -> f (NonEmpty UserStackAssociation))
-> NonEmpty UserStackAssociation
-> f (NonEmpty UserStackAssociation)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData BatchAssociateUserStack

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

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

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

-- | /See:/ 'newBatchAssociateUserStackResponse' smart constructor.
data BatchAssociateUserStackResponse = BatchAssociateUserStackResponse'
  { -- | The list of UserStackAssociationError objects.
    BatchAssociateUserStackResponse
-> Maybe [UserStackAssociationError]
errors :: Prelude.Maybe [UserStackAssociationError],
    -- | The response's http status code.
    BatchAssociateUserStackResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (BatchAssociateUserStackResponse
-> BatchAssociateUserStackResponse -> Bool
(BatchAssociateUserStackResponse
 -> BatchAssociateUserStackResponse -> Bool)
-> (BatchAssociateUserStackResponse
    -> BatchAssociateUserStackResponse -> Bool)
-> Eq BatchAssociateUserStackResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BatchAssociateUserStackResponse
-> BatchAssociateUserStackResponse -> Bool
$c/= :: BatchAssociateUserStackResponse
-> BatchAssociateUserStackResponse -> Bool
== :: BatchAssociateUserStackResponse
-> BatchAssociateUserStackResponse -> Bool
$c== :: BatchAssociateUserStackResponse
-> BatchAssociateUserStackResponse -> Bool
Prelude.Eq, Int -> BatchAssociateUserStackResponse -> ShowS
[BatchAssociateUserStackResponse] -> ShowS
BatchAssociateUserStackResponse -> String
(Int -> BatchAssociateUserStackResponse -> ShowS)
-> (BatchAssociateUserStackResponse -> String)
-> ([BatchAssociateUserStackResponse] -> ShowS)
-> Show BatchAssociateUserStackResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BatchAssociateUserStackResponse] -> ShowS
$cshowList :: [BatchAssociateUserStackResponse] -> ShowS
show :: BatchAssociateUserStackResponse -> String
$cshow :: BatchAssociateUserStackResponse -> String
showsPrec :: Int -> BatchAssociateUserStackResponse -> ShowS
$cshowsPrec :: Int -> BatchAssociateUserStackResponse -> ShowS
Prelude.Show, (forall x.
 BatchAssociateUserStackResponse
 -> Rep BatchAssociateUserStackResponse x)
-> (forall x.
    Rep BatchAssociateUserStackResponse x
    -> BatchAssociateUserStackResponse)
-> Generic BatchAssociateUserStackResponse
forall x.
Rep BatchAssociateUserStackResponse x
-> BatchAssociateUserStackResponse
forall x.
BatchAssociateUserStackResponse
-> Rep BatchAssociateUserStackResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep BatchAssociateUserStackResponse x
-> BatchAssociateUserStackResponse
$cfrom :: forall x.
BatchAssociateUserStackResponse
-> Rep BatchAssociateUserStackResponse x
Prelude.Generic)

-- |
-- Create a value of 'BatchAssociateUserStackResponse' 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:
--
-- 'errors', 'batchAssociateUserStackResponse_errors' - The list of UserStackAssociationError objects.
--
-- 'httpStatus', 'batchAssociateUserStackResponse_httpStatus' - The response's http status code.
newBatchAssociateUserStackResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  BatchAssociateUserStackResponse
newBatchAssociateUserStackResponse :: Int -> BatchAssociateUserStackResponse
newBatchAssociateUserStackResponse Int
pHttpStatus_ =
  BatchAssociateUserStackResponse' :: Maybe [UserStackAssociationError]
-> Int -> BatchAssociateUserStackResponse
BatchAssociateUserStackResponse'
    { $sel:errors:BatchAssociateUserStackResponse' :: Maybe [UserStackAssociationError]
errors =
        Maybe [UserStackAssociationError]
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:BatchAssociateUserStackResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The list of UserStackAssociationError objects.
batchAssociateUserStackResponse_errors :: Lens.Lens' BatchAssociateUserStackResponse (Prelude.Maybe [UserStackAssociationError])
batchAssociateUserStackResponse_errors :: (Maybe [UserStackAssociationError]
 -> f (Maybe [UserStackAssociationError]))
-> BatchAssociateUserStackResponse
-> f BatchAssociateUserStackResponse
batchAssociateUserStackResponse_errors = (BatchAssociateUserStackResponse
 -> Maybe [UserStackAssociationError])
-> (BatchAssociateUserStackResponse
    -> Maybe [UserStackAssociationError]
    -> BatchAssociateUserStackResponse)
-> Lens
     BatchAssociateUserStackResponse
     BatchAssociateUserStackResponse
     (Maybe [UserStackAssociationError])
     (Maybe [UserStackAssociationError])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchAssociateUserStackResponse' {Maybe [UserStackAssociationError]
errors :: Maybe [UserStackAssociationError]
$sel:errors:BatchAssociateUserStackResponse' :: BatchAssociateUserStackResponse
-> Maybe [UserStackAssociationError]
errors} -> Maybe [UserStackAssociationError]
errors) (\s :: BatchAssociateUserStackResponse
s@BatchAssociateUserStackResponse' {} Maybe [UserStackAssociationError]
a -> BatchAssociateUserStackResponse
s {$sel:errors:BatchAssociateUserStackResponse' :: Maybe [UserStackAssociationError]
errors = Maybe [UserStackAssociationError]
a} :: BatchAssociateUserStackResponse) ((Maybe [UserStackAssociationError]
  -> f (Maybe [UserStackAssociationError]))
 -> BatchAssociateUserStackResponse
 -> f BatchAssociateUserStackResponse)
-> ((Maybe [UserStackAssociationError]
     -> f (Maybe [UserStackAssociationError]))
    -> Maybe [UserStackAssociationError]
    -> f (Maybe [UserStackAssociationError]))
-> (Maybe [UserStackAssociationError]
    -> f (Maybe [UserStackAssociationError]))
-> BatchAssociateUserStackResponse
-> f BatchAssociateUserStackResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [UserStackAssociationError]
  [UserStackAssociationError]
  [UserStackAssociationError]
  [UserStackAssociationError]
-> Iso
     (Maybe [UserStackAssociationError])
     (Maybe [UserStackAssociationError])
     (Maybe [UserStackAssociationError])
     (Maybe [UserStackAssociationError])
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
  [UserStackAssociationError]
  [UserStackAssociationError]
  [UserStackAssociationError]
  [UserStackAssociationError]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance
  Prelude.NFData
    BatchAssociateUserStackResponse