{-# 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.Chime.BatchUpdateUser
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Updates user details within the UpdateUserRequestItem object for up to
-- 20 users for the specified Amazon Chime account. Currently, only
-- @LicenseType@ updates are supported for this action.
module Amazonka.Chime.BatchUpdateUser
  ( -- * Creating a Request
    BatchUpdateUser (..),
    newBatchUpdateUser,

    -- * Request Lenses
    batchUpdateUser_accountId,
    batchUpdateUser_updateUserRequestItems,

    -- * Destructuring the Response
    BatchUpdateUserResponse (..),
    newBatchUpdateUserResponse,

    -- * Response Lenses
    batchUpdateUserResponse_userErrors,
    batchUpdateUserResponse_httpStatus,
  )
where

import Amazonka.Chime.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:/ 'newBatchUpdateUser' smart constructor.
data BatchUpdateUser = BatchUpdateUser'
  { -- | The Amazon Chime account ID.
    BatchUpdateUser -> Text
accountId :: Prelude.Text,
    -- | The request containing the user IDs and details to update.
    BatchUpdateUser -> [UpdateUserRequestItem]
updateUserRequestItems :: [UpdateUserRequestItem]
  }
  deriving (BatchUpdateUser -> BatchUpdateUser -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BatchUpdateUser -> BatchUpdateUser -> Bool
$c/= :: BatchUpdateUser -> BatchUpdateUser -> Bool
== :: BatchUpdateUser -> BatchUpdateUser -> Bool
$c== :: BatchUpdateUser -> BatchUpdateUser -> Bool
Prelude.Eq, Int -> BatchUpdateUser -> ShowS
[BatchUpdateUser] -> ShowS
BatchUpdateUser -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BatchUpdateUser] -> ShowS
$cshowList :: [BatchUpdateUser] -> ShowS
show :: BatchUpdateUser -> String
$cshow :: BatchUpdateUser -> String
showsPrec :: Int -> BatchUpdateUser -> ShowS
$cshowsPrec :: Int -> BatchUpdateUser -> ShowS
Prelude.Show, forall x. Rep BatchUpdateUser x -> BatchUpdateUser
forall x. BatchUpdateUser -> Rep BatchUpdateUser x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BatchUpdateUser x -> BatchUpdateUser
$cfrom :: forall x. BatchUpdateUser -> Rep BatchUpdateUser x
Prelude.Generic)

-- |
-- Create a value of 'BatchUpdateUser' 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:
--
-- 'accountId', 'batchUpdateUser_accountId' - The Amazon Chime account ID.
--
-- 'updateUserRequestItems', 'batchUpdateUser_updateUserRequestItems' - The request containing the user IDs and details to update.
newBatchUpdateUser ::
  -- | 'accountId'
  Prelude.Text ->
  BatchUpdateUser
newBatchUpdateUser :: Text -> BatchUpdateUser
newBatchUpdateUser Text
pAccountId_ =
  BatchUpdateUser'
    { $sel:accountId:BatchUpdateUser' :: Text
accountId = Text
pAccountId_,
      $sel:updateUserRequestItems:BatchUpdateUser' :: [UpdateUserRequestItem]
updateUserRequestItems = forall a. Monoid a => a
Prelude.mempty
    }

-- | The Amazon Chime account ID.
batchUpdateUser_accountId :: Lens.Lens' BatchUpdateUser Prelude.Text
batchUpdateUser_accountId :: Lens' BatchUpdateUser Text
batchUpdateUser_accountId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchUpdateUser' {Text
accountId :: Text
$sel:accountId:BatchUpdateUser' :: BatchUpdateUser -> Text
accountId} -> Text
accountId) (\s :: BatchUpdateUser
s@BatchUpdateUser' {} Text
a -> BatchUpdateUser
s {$sel:accountId:BatchUpdateUser' :: Text
accountId = Text
a} :: BatchUpdateUser)

-- | The request containing the user IDs and details to update.
batchUpdateUser_updateUserRequestItems :: Lens.Lens' BatchUpdateUser [UpdateUserRequestItem]
batchUpdateUser_updateUserRequestItems :: Lens' BatchUpdateUser [UpdateUserRequestItem]
batchUpdateUser_updateUserRequestItems = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchUpdateUser' {[UpdateUserRequestItem]
updateUserRequestItems :: [UpdateUserRequestItem]
$sel:updateUserRequestItems:BatchUpdateUser' :: BatchUpdateUser -> [UpdateUserRequestItem]
updateUserRequestItems} -> [UpdateUserRequestItem]
updateUserRequestItems) (\s :: BatchUpdateUser
s@BatchUpdateUser' {} [UpdateUserRequestItem]
a -> BatchUpdateUser
s {$sel:updateUserRequestItems:BatchUpdateUser' :: [UpdateUserRequestItem]
updateUserRequestItems = [UpdateUserRequestItem]
a} :: BatchUpdateUser) 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 BatchUpdateUser where
  type
    AWSResponse BatchUpdateUser =
      BatchUpdateUserResponse
  request :: (Service -> Service) -> BatchUpdateUser -> Request BatchUpdateUser
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 BatchUpdateUser
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse BatchUpdateUser)))
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 [UserError] -> Int -> BatchUpdateUserResponse
BatchUpdateUserResponse'
            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
"UserErrors" 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 BatchUpdateUser where
  hashWithSalt :: Int -> BatchUpdateUser -> Int
hashWithSalt Int
_salt BatchUpdateUser' {[UpdateUserRequestItem]
Text
updateUserRequestItems :: [UpdateUserRequestItem]
accountId :: Text
$sel:updateUserRequestItems:BatchUpdateUser' :: BatchUpdateUser -> [UpdateUserRequestItem]
$sel:accountId:BatchUpdateUser' :: BatchUpdateUser -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
accountId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [UpdateUserRequestItem]
updateUserRequestItems

instance Prelude.NFData BatchUpdateUser where
  rnf :: BatchUpdateUser -> ()
rnf BatchUpdateUser' {[UpdateUserRequestItem]
Text
updateUserRequestItems :: [UpdateUserRequestItem]
accountId :: Text
$sel:updateUserRequestItems:BatchUpdateUser' :: BatchUpdateUser -> [UpdateUserRequestItem]
$sel:accountId:BatchUpdateUser' :: BatchUpdateUser -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
accountId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [UpdateUserRequestItem]
updateUserRequestItems

instance Data.ToHeaders BatchUpdateUser where
  toHeaders :: BatchUpdateUser -> ResponseHeaders
toHeaders = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

instance Data.ToJSON BatchUpdateUser where
  toJSON :: BatchUpdateUser -> Value
toJSON BatchUpdateUser' {[UpdateUserRequestItem]
Text
updateUserRequestItems :: [UpdateUserRequestItem]
accountId :: Text
$sel:updateUserRequestItems:BatchUpdateUser' :: BatchUpdateUser -> [UpdateUserRequestItem]
$sel:accountId:BatchUpdateUser' :: BatchUpdateUser -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just
              ( Key
"UpdateUserRequestItems"
                  forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= [UpdateUserRequestItem]
updateUserRequestItems
              )
          ]
      )

instance Data.ToPath BatchUpdateUser where
  toPath :: BatchUpdateUser -> ByteString
toPath BatchUpdateUser' {[UpdateUserRequestItem]
Text
updateUserRequestItems :: [UpdateUserRequestItem]
accountId :: Text
$sel:updateUserRequestItems:BatchUpdateUser' :: BatchUpdateUser -> [UpdateUserRequestItem]
$sel:accountId:BatchUpdateUser' :: BatchUpdateUser -> Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/accounts/", forall a. ToByteString a => a -> ByteString
Data.toBS Text
accountId, ByteString
"/users"]

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

-- | /See:/ 'newBatchUpdateUserResponse' smart constructor.
data BatchUpdateUserResponse = BatchUpdateUserResponse'
  { -- | If the BatchUpdateUser action fails for one or more of the user IDs in
    -- the request, a list of the user IDs is returned, along with error codes
    -- and error messages.
    BatchUpdateUserResponse -> Maybe [UserError]
userErrors :: Prelude.Maybe [UserError],
    -- | The response's http status code.
    BatchUpdateUserResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (BatchUpdateUserResponse -> BatchUpdateUserResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BatchUpdateUserResponse -> BatchUpdateUserResponse -> Bool
$c/= :: BatchUpdateUserResponse -> BatchUpdateUserResponse -> Bool
== :: BatchUpdateUserResponse -> BatchUpdateUserResponse -> Bool
$c== :: BatchUpdateUserResponse -> BatchUpdateUserResponse -> Bool
Prelude.Eq, ReadPrec [BatchUpdateUserResponse]
ReadPrec BatchUpdateUserResponse
Int -> ReadS BatchUpdateUserResponse
ReadS [BatchUpdateUserResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BatchUpdateUserResponse]
$creadListPrec :: ReadPrec [BatchUpdateUserResponse]
readPrec :: ReadPrec BatchUpdateUserResponse
$creadPrec :: ReadPrec BatchUpdateUserResponse
readList :: ReadS [BatchUpdateUserResponse]
$creadList :: ReadS [BatchUpdateUserResponse]
readsPrec :: Int -> ReadS BatchUpdateUserResponse
$creadsPrec :: Int -> ReadS BatchUpdateUserResponse
Prelude.Read, Int -> BatchUpdateUserResponse -> ShowS
[BatchUpdateUserResponse] -> ShowS
BatchUpdateUserResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BatchUpdateUserResponse] -> ShowS
$cshowList :: [BatchUpdateUserResponse] -> ShowS
show :: BatchUpdateUserResponse -> String
$cshow :: BatchUpdateUserResponse -> String
showsPrec :: Int -> BatchUpdateUserResponse -> ShowS
$cshowsPrec :: Int -> BatchUpdateUserResponse -> ShowS
Prelude.Show, forall x. Rep BatchUpdateUserResponse x -> BatchUpdateUserResponse
forall x. BatchUpdateUserResponse -> Rep BatchUpdateUserResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BatchUpdateUserResponse x -> BatchUpdateUserResponse
$cfrom :: forall x. BatchUpdateUserResponse -> Rep BatchUpdateUserResponse x
Prelude.Generic)

-- |
-- Create a value of 'BatchUpdateUserResponse' 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:
--
-- 'userErrors', 'batchUpdateUserResponse_userErrors' - If the BatchUpdateUser action fails for one or more of the user IDs in
-- the request, a list of the user IDs is returned, along with error codes
-- and error messages.
--
-- 'httpStatus', 'batchUpdateUserResponse_httpStatus' - The response's http status code.
newBatchUpdateUserResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  BatchUpdateUserResponse
newBatchUpdateUserResponse :: Int -> BatchUpdateUserResponse
newBatchUpdateUserResponse Int
pHttpStatus_ =
  BatchUpdateUserResponse'
    { $sel:userErrors:BatchUpdateUserResponse' :: Maybe [UserError]
userErrors =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:BatchUpdateUserResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | If the BatchUpdateUser action fails for one or more of the user IDs in
-- the request, a list of the user IDs is returned, along with error codes
-- and error messages.
batchUpdateUserResponse_userErrors :: Lens.Lens' BatchUpdateUserResponse (Prelude.Maybe [UserError])
batchUpdateUserResponse_userErrors :: Lens' BatchUpdateUserResponse (Maybe [UserError])
batchUpdateUserResponse_userErrors = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchUpdateUserResponse' {Maybe [UserError]
userErrors :: Maybe [UserError]
$sel:userErrors:BatchUpdateUserResponse' :: BatchUpdateUserResponse -> Maybe [UserError]
userErrors} -> Maybe [UserError]
userErrors) (\s :: BatchUpdateUserResponse
s@BatchUpdateUserResponse' {} Maybe [UserError]
a -> BatchUpdateUserResponse
s {$sel:userErrors:BatchUpdateUserResponse' :: Maybe [UserError]
userErrors = Maybe [UserError]
a} :: BatchUpdateUserResponse) 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.
batchUpdateUserResponse_httpStatus :: Lens.Lens' BatchUpdateUserResponse Prelude.Int
batchUpdateUserResponse_httpStatus :: Lens' BatchUpdateUserResponse Int
batchUpdateUserResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchUpdateUserResponse' {Int
httpStatus :: Int
$sel:httpStatus:BatchUpdateUserResponse' :: BatchUpdateUserResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: BatchUpdateUserResponse
s@BatchUpdateUserResponse' {} Int
a -> BatchUpdateUserResponse
s {$sel:httpStatus:BatchUpdateUserResponse' :: Int
httpStatus = Int
a} :: BatchUpdateUserResponse)

instance Prelude.NFData BatchUpdateUserResponse where
  rnf :: BatchUpdateUserResponse -> ()
rnf BatchUpdateUserResponse' {Int
Maybe [UserError]
httpStatus :: Int
userErrors :: Maybe [UserError]
$sel:httpStatus:BatchUpdateUserResponse' :: BatchUpdateUserResponse -> Int
$sel:userErrors:BatchUpdateUserResponse' :: BatchUpdateUserResponse -> Maybe [UserError]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [UserError]
userErrors
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus