{-# 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.ElastiCache.ModifyUserGroup
-- 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)
--
-- Changes the list of users that belong to the user group.
module Amazonka.ElastiCache.ModifyUserGroup
  ( -- * Creating a Request
    ModifyUserGroup (..),
    newModifyUserGroup,

    -- * Request Lenses
    modifyUserGroup_userIdsToAdd,
    modifyUserGroup_userIdsToRemove,
    modifyUserGroup_userGroupId,

    -- * Destructuring the Response
    UserGroup (..),
    newUserGroup,

    -- * Response Lenses
    userGroup_status,
    userGroup_userIds,
    userGroup_arn,
    userGroup_userGroupId,
    userGroup_engine,
    userGroup_pendingChanges,
    userGroup_replicationGroups,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.ElastiCache.Types
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:/ 'newModifyUserGroup' smart constructor.
data ModifyUserGroup = ModifyUserGroup'
  { -- | The list of user IDs to add to the user group.
    ModifyUserGroup -> Maybe (NonEmpty Text)
userIdsToAdd :: Prelude.Maybe (Prelude.NonEmpty Prelude.Text),
    -- | The list of user IDs to remove from the user group.
    ModifyUserGroup -> Maybe (NonEmpty Text)
userIdsToRemove :: Prelude.Maybe (Prelude.NonEmpty Prelude.Text),
    -- | The ID of the user group.
    ModifyUserGroup -> Text
userGroupId :: Prelude.Text
  }
  deriving (ModifyUserGroup -> ModifyUserGroup -> Bool
(ModifyUserGroup -> ModifyUserGroup -> Bool)
-> (ModifyUserGroup -> ModifyUserGroup -> Bool)
-> Eq ModifyUserGroup
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ModifyUserGroup -> ModifyUserGroup -> Bool
$c/= :: ModifyUserGroup -> ModifyUserGroup -> Bool
== :: ModifyUserGroup -> ModifyUserGroup -> Bool
$c== :: ModifyUserGroup -> ModifyUserGroup -> Bool
Prelude.Eq, ReadPrec [ModifyUserGroup]
ReadPrec ModifyUserGroup
Int -> ReadS ModifyUserGroup
ReadS [ModifyUserGroup]
(Int -> ReadS ModifyUserGroup)
-> ReadS [ModifyUserGroup]
-> ReadPrec ModifyUserGroup
-> ReadPrec [ModifyUserGroup]
-> Read ModifyUserGroup
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ModifyUserGroup]
$creadListPrec :: ReadPrec [ModifyUserGroup]
readPrec :: ReadPrec ModifyUserGroup
$creadPrec :: ReadPrec ModifyUserGroup
readList :: ReadS [ModifyUserGroup]
$creadList :: ReadS [ModifyUserGroup]
readsPrec :: Int -> ReadS ModifyUserGroup
$creadsPrec :: Int -> ReadS ModifyUserGroup
Prelude.Read, Int -> ModifyUserGroup -> ShowS
[ModifyUserGroup] -> ShowS
ModifyUserGroup -> String
(Int -> ModifyUserGroup -> ShowS)
-> (ModifyUserGroup -> String)
-> ([ModifyUserGroup] -> ShowS)
-> Show ModifyUserGroup
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ModifyUserGroup] -> ShowS
$cshowList :: [ModifyUserGroup] -> ShowS
show :: ModifyUserGroup -> String
$cshow :: ModifyUserGroup -> String
showsPrec :: Int -> ModifyUserGroup -> ShowS
$cshowsPrec :: Int -> ModifyUserGroup -> ShowS
Prelude.Show, (forall x. ModifyUserGroup -> Rep ModifyUserGroup x)
-> (forall x. Rep ModifyUserGroup x -> ModifyUserGroup)
-> Generic ModifyUserGroup
forall x. Rep ModifyUserGroup x -> ModifyUserGroup
forall x. ModifyUserGroup -> Rep ModifyUserGroup x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ModifyUserGroup x -> ModifyUserGroup
$cfrom :: forall x. ModifyUserGroup -> Rep ModifyUserGroup x
Prelude.Generic)

-- |
-- Create a value of 'ModifyUserGroup' 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:
--
-- 'userIdsToAdd', 'modifyUserGroup_userIdsToAdd' - The list of user IDs to add to the user group.
--
-- 'userIdsToRemove', 'modifyUserGroup_userIdsToRemove' - The list of user IDs to remove from the user group.
--
-- 'userGroupId', 'modifyUserGroup_userGroupId' - The ID of the user group.
newModifyUserGroup ::
  -- | 'userGroupId'
  Prelude.Text ->
  ModifyUserGroup
newModifyUserGroup :: Text -> ModifyUserGroup
newModifyUserGroup Text
pUserGroupId_ =
  ModifyUserGroup' :: Maybe (NonEmpty Text)
-> Maybe (NonEmpty Text) -> Text -> ModifyUserGroup
ModifyUserGroup'
    { $sel:userIdsToAdd:ModifyUserGroup' :: Maybe (NonEmpty Text)
userIdsToAdd = Maybe (NonEmpty Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:userIdsToRemove:ModifyUserGroup' :: Maybe (NonEmpty Text)
userIdsToRemove = Maybe (NonEmpty Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:userGroupId:ModifyUserGroup' :: Text
userGroupId = Text
pUserGroupId_
    }

-- | The list of user IDs to add to the user group.
modifyUserGroup_userIdsToAdd :: Lens.Lens' ModifyUserGroup (Prelude.Maybe (Prelude.NonEmpty Prelude.Text))
modifyUserGroup_userIdsToAdd :: (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> ModifyUserGroup -> f ModifyUserGroup
modifyUserGroup_userIdsToAdd = (ModifyUserGroup -> Maybe (NonEmpty Text))
-> (ModifyUserGroup -> Maybe (NonEmpty Text) -> ModifyUserGroup)
-> Lens
     ModifyUserGroup
     ModifyUserGroup
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ModifyUserGroup' {Maybe (NonEmpty Text)
userIdsToAdd :: Maybe (NonEmpty Text)
$sel:userIdsToAdd:ModifyUserGroup' :: ModifyUserGroup -> Maybe (NonEmpty Text)
userIdsToAdd} -> Maybe (NonEmpty Text)
userIdsToAdd) (\s :: ModifyUserGroup
s@ModifyUserGroup' {} Maybe (NonEmpty Text)
a -> ModifyUserGroup
s {$sel:userIdsToAdd:ModifyUserGroup' :: Maybe (NonEmpty Text)
userIdsToAdd = Maybe (NonEmpty Text)
a} :: ModifyUserGroup) ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
 -> ModifyUserGroup -> f ModifyUserGroup)
-> ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
    -> Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> ModifyUserGroup
-> f ModifyUserGroup
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty Text) (NonEmpty Text) (NonEmpty Text) (NonEmpty Text)
-> Iso
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
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
  (NonEmpty Text) (NonEmpty Text) (NonEmpty Text) (NonEmpty Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The list of user IDs to remove from the user group.
modifyUserGroup_userIdsToRemove :: Lens.Lens' ModifyUserGroup (Prelude.Maybe (Prelude.NonEmpty Prelude.Text))
modifyUserGroup_userIdsToRemove :: (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> ModifyUserGroup -> f ModifyUserGroup
modifyUserGroup_userIdsToRemove = (ModifyUserGroup -> Maybe (NonEmpty Text))
-> (ModifyUserGroup -> Maybe (NonEmpty Text) -> ModifyUserGroup)
-> Lens
     ModifyUserGroup
     ModifyUserGroup
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ModifyUserGroup' {Maybe (NonEmpty Text)
userIdsToRemove :: Maybe (NonEmpty Text)
$sel:userIdsToRemove:ModifyUserGroup' :: ModifyUserGroup -> Maybe (NonEmpty Text)
userIdsToRemove} -> Maybe (NonEmpty Text)
userIdsToRemove) (\s :: ModifyUserGroup
s@ModifyUserGroup' {} Maybe (NonEmpty Text)
a -> ModifyUserGroup
s {$sel:userIdsToRemove:ModifyUserGroup' :: Maybe (NonEmpty Text)
userIdsToRemove = Maybe (NonEmpty Text)
a} :: ModifyUserGroup) ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
 -> ModifyUserGroup -> f ModifyUserGroup)
-> ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
    -> Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> ModifyUserGroup
-> f ModifyUserGroup
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty Text) (NonEmpty Text) (NonEmpty Text) (NonEmpty Text)
-> Iso
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
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
  (NonEmpty Text) (NonEmpty Text) (NonEmpty Text) (NonEmpty Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The ID of the user group.
modifyUserGroup_userGroupId :: Lens.Lens' ModifyUserGroup Prelude.Text
modifyUserGroup_userGroupId :: (Text -> f Text) -> ModifyUserGroup -> f ModifyUserGroup
modifyUserGroup_userGroupId = (ModifyUserGroup -> Text)
-> (ModifyUserGroup -> Text -> ModifyUserGroup)
-> Lens ModifyUserGroup ModifyUserGroup Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ModifyUserGroup' {Text
userGroupId :: Text
$sel:userGroupId:ModifyUserGroup' :: ModifyUserGroup -> Text
userGroupId} -> Text
userGroupId) (\s :: ModifyUserGroup
s@ModifyUserGroup' {} Text
a -> ModifyUserGroup
s {$sel:userGroupId:ModifyUserGroup' :: Text
userGroupId = Text
a} :: ModifyUserGroup)

instance Core.AWSRequest ModifyUserGroup where
  type AWSResponse ModifyUserGroup = UserGroup
  request :: ModifyUserGroup -> Request ModifyUserGroup
request = Service -> ModifyUserGroup -> Request ModifyUserGroup
forall a. ToRequest a => Service -> a -> Request a
Request.postQuery Service
defaultService
  response :: Logger
-> Service
-> Proxy ModifyUserGroup
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ModifyUserGroup)))
response =
    Text
-> (Int
    -> ResponseHeaders
    -> [Node]
    -> Either String (AWSResponse ModifyUserGroup))
-> Logger
-> Service
-> Proxy ModifyUserGroup
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ModifyUserGroup)))
forall (m :: * -> *) a.
MonadResource m =>
Text
-> (Int
    -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveXMLWrapper
      Text
"ModifyUserGroupResult"
      (\Int
s ResponseHeaders
h [Node]
x -> [Node] -> Either String UserGroup
forall a. FromXML a => [Node] -> Either String a
Core.parseXML [Node]
x)

instance Prelude.Hashable ModifyUserGroup

instance Prelude.NFData ModifyUserGroup

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

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

instance Core.ToQuery ModifyUserGroup where
  toQuery :: ModifyUserGroup -> QueryString
toQuery ModifyUserGroup' {Maybe (NonEmpty Text)
Text
userGroupId :: Text
userIdsToRemove :: Maybe (NonEmpty Text)
userIdsToAdd :: Maybe (NonEmpty Text)
$sel:userGroupId:ModifyUserGroup' :: ModifyUserGroup -> Text
$sel:userIdsToRemove:ModifyUserGroup' :: ModifyUserGroup -> Maybe (NonEmpty Text)
$sel:userIdsToAdd:ModifyUserGroup' :: ModifyUserGroup -> Maybe (NonEmpty Text)
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"ModifyUserGroup" :: Prelude.ByteString),
        ByteString
"Version"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"2015-02-02" :: Prelude.ByteString),
        ByteString
"UserIdsToAdd"
          ByteString -> QueryString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe QueryString -> QueryString
forall a. ToQuery a => a -> QueryString
Core.toQuery
            (ByteString -> NonEmpty Text -> QueryString
forall a.
(IsList a, ToQuery (Item a)) =>
ByteString -> a -> QueryString
Core.toQueryList ByteString
"member" (NonEmpty Text -> QueryString)
-> Maybe (NonEmpty Text) -> Maybe QueryString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty Text)
userIdsToAdd),
        ByteString
"UserIdsToRemove"
          ByteString -> QueryString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe QueryString -> QueryString
forall a. ToQuery a => a -> QueryString
Core.toQuery
            ( ByteString -> NonEmpty Text -> QueryString
forall a.
(IsList a, ToQuery (Item a)) =>
ByteString -> a -> QueryString
Core.toQueryList ByteString
"member"
                (NonEmpty Text -> QueryString)
-> Maybe (NonEmpty Text) -> Maybe QueryString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty Text)
userIdsToRemove
            ),
        ByteString
"UserGroupId" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
userGroupId
      ]