{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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
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. 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'
    { $sel:userStackAssociations:BatchAssociateUserStack' :: NonEmpty UserStackAssociation
userStackAssociations =
        forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced 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 :: Lens' BatchAssociateUserStack (NonEmpty UserStackAssociation)
batchAssociateUserStack_userStackAssociations = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 :: (Service -> Service)
-> BatchAssociateUserStack -> Request BatchAssociateUserStack
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 BatchAssociateUserStack
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse BatchAssociateUserStack)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe [UserStackAssociationError]
-> Int -> BatchAssociateUserStackResponse
BatchAssociateUserStackResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"errors" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => 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 BatchAssociateUserStack where
  hashWithSalt :: Int -> BatchAssociateUserStack -> Int
hashWithSalt Int
_salt BatchAssociateUserStack' {NonEmpty UserStackAssociation
userStackAssociations :: NonEmpty UserStackAssociation
$sel:userStackAssociations:BatchAssociateUserStack' :: BatchAssociateUserStack -> NonEmpty UserStackAssociation
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty UserStackAssociation
userStackAssociations

instance Prelude.NFData BatchAssociateUserStack where
  rnf :: BatchAssociateUserStack -> ()
rnf BatchAssociateUserStack' {NonEmpty UserStackAssociation
userStackAssociations :: NonEmpty UserStackAssociation
$sel:userStackAssociations:BatchAssociateUserStack' :: BatchAssociateUserStack -> NonEmpty UserStackAssociation
..} =
    forall a. NFData a => a -> ()
Prelude.rnf NonEmpty UserStackAssociation
userStackAssociations

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

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

instance Data.ToQuery BatchAssociateUserStack where
  toQuery :: BatchAssociateUserStack -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const 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
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
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.
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'
    { $sel:errors:BatchAssociateUserStackResponse' :: Maybe [UserStackAssociationError]
errors =
        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 :: Lens'
  BatchAssociateUserStackResponse (Maybe [UserStackAssociationError])
batchAssociateUserStackResponse_errors = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 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 :: Lens' BatchAssociateUserStackResponse Int
batchAssociateUserStackResponse_httpStatus = 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
  where
  rnf :: BatchAssociateUserStackResponse -> ()
rnf BatchAssociateUserStackResponse' {Int
Maybe [UserStackAssociationError]
httpStatus :: Int
errors :: Maybe [UserStackAssociationError]
$sel:httpStatus:BatchAssociateUserStackResponse' :: BatchAssociateUserStackResponse -> Int
$sel:errors:BatchAssociateUserStackResponse' :: BatchAssociateUserStackResponse
-> Maybe [UserStackAssociationError]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [UserStackAssociationError]
errors
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus