{-# 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.ChimeSDKMessaging.CreateChannelBan
-- 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)
--
-- Permanently bans a member from a channel. Moderators can\'t add banned
-- members to a channel. To undo a ban, you first have to
-- @DeleteChannelBan@, and then @CreateChannelMembership@. Bans are cleaned
-- up when you delete users or channels.
--
-- If you ban a user who is already part of a channel, that user is
-- automatically kicked from the channel.
--
-- The @x-amz-chime-bearer@ request header is mandatory. Use the
-- @AppInstanceUserArn@ of the user that makes the API call as the value in
-- the header.
module Amazonka.ChimeSDKMessaging.CreateChannelBan
  ( -- * Creating a Request
    CreateChannelBan (..),
    newCreateChannelBan,

    -- * Request Lenses
    createChannelBan_channelArn,
    createChannelBan_memberArn,
    createChannelBan_chimeBearer,

    -- * Destructuring the Response
    CreateChannelBanResponse (..),
    newCreateChannelBanResponse,

    -- * Response Lenses
    createChannelBanResponse_channelArn,
    createChannelBanResponse_member,
    createChannelBanResponse_httpStatus,
  )
where

import Amazonka.ChimeSDKMessaging.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:/ 'newCreateChannelBan' smart constructor.
data CreateChannelBan = CreateChannelBan'
  { -- | The ARN of the ban request.
    CreateChannelBan -> Text
channelArn :: Prelude.Text,
    -- | The ARN of the member being banned.
    CreateChannelBan -> Text
memberArn :: Prelude.Text,
    -- | The @AppInstanceUserArn@ of the user that makes the API call.
    CreateChannelBan -> Text
chimeBearer :: Prelude.Text
  }
  deriving (CreateChannelBan -> CreateChannelBan -> Bool
(CreateChannelBan -> CreateChannelBan -> Bool)
-> (CreateChannelBan -> CreateChannelBan -> Bool)
-> Eq CreateChannelBan
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateChannelBan -> CreateChannelBan -> Bool
$c/= :: CreateChannelBan -> CreateChannelBan -> Bool
== :: CreateChannelBan -> CreateChannelBan -> Bool
$c== :: CreateChannelBan -> CreateChannelBan -> Bool
Prelude.Eq, ReadPrec [CreateChannelBan]
ReadPrec CreateChannelBan
Int -> ReadS CreateChannelBan
ReadS [CreateChannelBan]
(Int -> ReadS CreateChannelBan)
-> ReadS [CreateChannelBan]
-> ReadPrec CreateChannelBan
-> ReadPrec [CreateChannelBan]
-> Read CreateChannelBan
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateChannelBan]
$creadListPrec :: ReadPrec [CreateChannelBan]
readPrec :: ReadPrec CreateChannelBan
$creadPrec :: ReadPrec CreateChannelBan
readList :: ReadS [CreateChannelBan]
$creadList :: ReadS [CreateChannelBan]
readsPrec :: Int -> ReadS CreateChannelBan
$creadsPrec :: Int -> ReadS CreateChannelBan
Prelude.Read, Int -> CreateChannelBan -> ShowS
[CreateChannelBan] -> ShowS
CreateChannelBan -> String
(Int -> CreateChannelBan -> ShowS)
-> (CreateChannelBan -> String)
-> ([CreateChannelBan] -> ShowS)
-> Show CreateChannelBan
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateChannelBan] -> ShowS
$cshowList :: [CreateChannelBan] -> ShowS
show :: CreateChannelBan -> String
$cshow :: CreateChannelBan -> String
showsPrec :: Int -> CreateChannelBan -> ShowS
$cshowsPrec :: Int -> CreateChannelBan -> ShowS
Prelude.Show, (forall x. CreateChannelBan -> Rep CreateChannelBan x)
-> (forall x. Rep CreateChannelBan x -> CreateChannelBan)
-> Generic CreateChannelBan
forall x. Rep CreateChannelBan x -> CreateChannelBan
forall x. CreateChannelBan -> Rep CreateChannelBan x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateChannelBan x -> CreateChannelBan
$cfrom :: forall x. CreateChannelBan -> Rep CreateChannelBan x
Prelude.Generic)

-- |
-- Create a value of 'CreateChannelBan' 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:
--
-- 'channelArn', 'createChannelBan_channelArn' - The ARN of the ban request.
--
-- 'memberArn', 'createChannelBan_memberArn' - The ARN of the member being banned.
--
-- 'chimeBearer', 'createChannelBan_chimeBearer' - The @AppInstanceUserArn@ of the user that makes the API call.
newCreateChannelBan ::
  -- | 'channelArn'
  Prelude.Text ->
  -- | 'memberArn'
  Prelude.Text ->
  -- | 'chimeBearer'
  Prelude.Text ->
  CreateChannelBan
newCreateChannelBan :: Text -> Text -> Text -> CreateChannelBan
newCreateChannelBan
  Text
pChannelArn_
  Text
pMemberArn_
  Text
pChimeBearer_ =
    CreateChannelBan' :: Text -> Text -> Text -> CreateChannelBan
CreateChannelBan'
      { $sel:channelArn:CreateChannelBan' :: Text
channelArn = Text
pChannelArn_,
        $sel:memberArn:CreateChannelBan' :: Text
memberArn = Text
pMemberArn_,
        $sel:chimeBearer:CreateChannelBan' :: Text
chimeBearer = Text
pChimeBearer_
      }

-- | The ARN of the ban request.
createChannelBan_channelArn :: Lens.Lens' CreateChannelBan Prelude.Text
createChannelBan_channelArn :: (Text -> f Text) -> CreateChannelBan -> f CreateChannelBan
createChannelBan_channelArn = (CreateChannelBan -> Text)
-> (CreateChannelBan -> Text -> CreateChannelBan)
-> Lens CreateChannelBan CreateChannelBan Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateChannelBan' {Text
channelArn :: Text
$sel:channelArn:CreateChannelBan' :: CreateChannelBan -> Text
channelArn} -> Text
channelArn) (\s :: CreateChannelBan
s@CreateChannelBan' {} Text
a -> CreateChannelBan
s {$sel:channelArn:CreateChannelBan' :: Text
channelArn = Text
a} :: CreateChannelBan)

-- | The ARN of the member being banned.
createChannelBan_memberArn :: Lens.Lens' CreateChannelBan Prelude.Text
createChannelBan_memberArn :: (Text -> f Text) -> CreateChannelBan -> f CreateChannelBan
createChannelBan_memberArn = (CreateChannelBan -> Text)
-> (CreateChannelBan -> Text -> CreateChannelBan)
-> Lens CreateChannelBan CreateChannelBan Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateChannelBan' {Text
memberArn :: Text
$sel:memberArn:CreateChannelBan' :: CreateChannelBan -> Text
memberArn} -> Text
memberArn) (\s :: CreateChannelBan
s@CreateChannelBan' {} Text
a -> CreateChannelBan
s {$sel:memberArn:CreateChannelBan' :: Text
memberArn = Text
a} :: CreateChannelBan)

-- | The @AppInstanceUserArn@ of the user that makes the API call.
createChannelBan_chimeBearer :: Lens.Lens' CreateChannelBan Prelude.Text
createChannelBan_chimeBearer :: (Text -> f Text) -> CreateChannelBan -> f CreateChannelBan
createChannelBan_chimeBearer = (CreateChannelBan -> Text)
-> (CreateChannelBan -> Text -> CreateChannelBan)
-> Lens CreateChannelBan CreateChannelBan Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateChannelBan' {Text
chimeBearer :: Text
$sel:chimeBearer:CreateChannelBan' :: CreateChannelBan -> Text
chimeBearer} -> Text
chimeBearer) (\s :: CreateChannelBan
s@CreateChannelBan' {} Text
a -> CreateChannelBan
s {$sel:chimeBearer:CreateChannelBan' :: Text
chimeBearer = Text
a} :: CreateChannelBan)

instance Core.AWSRequest CreateChannelBan where
  type
    AWSResponse CreateChannelBan =
      CreateChannelBanResponse
  request :: CreateChannelBan -> Request CreateChannelBan
request = Service -> CreateChannelBan -> Request CreateChannelBan
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateChannelBan
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateChannelBan)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse CreateChannelBan))
-> Logger
-> Service
-> Proxy CreateChannelBan
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateChannelBan)))
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 Text -> Maybe Identity -> Int -> CreateChannelBanResponse
CreateChannelBanResponse'
            (Maybe Text -> Maybe Identity -> Int -> CreateChannelBanResponse)
-> Either String (Maybe Text)
-> Either
     String (Maybe Identity -> Int -> CreateChannelBanResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"ChannelArn")
            Either String (Maybe Identity -> Int -> CreateChannelBanResponse)
-> Either String (Maybe Identity)
-> Either String (Int -> CreateChannelBanResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe Identity)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Member")
            Either String (Int -> CreateChannelBanResponse)
-> Either String Int -> Either String CreateChannelBanResponse
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 CreateChannelBan

instance Prelude.NFData CreateChannelBan

instance Core.ToHeaders CreateChannelBan where
  toHeaders :: CreateChannelBan -> ResponseHeaders
toHeaders CreateChannelBan' {Text
chimeBearer :: Text
memberArn :: Text
channelArn :: Text
$sel:chimeBearer:CreateChannelBan' :: CreateChannelBan -> Text
$sel:memberArn:CreateChannelBan' :: CreateChannelBan -> Text
$sel:channelArn:CreateChannelBan' :: CreateChannelBan -> Text
..} =
    [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [HeaderName
"x-amz-chime-bearer" HeaderName -> Text -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# Text
chimeBearer]

instance Core.ToJSON CreateChannelBan where
  toJSON :: CreateChannelBan -> Value
toJSON CreateChannelBan' {Text
chimeBearer :: Text
memberArn :: Text
channelArn :: Text
$sel:chimeBearer:CreateChannelBan' :: CreateChannelBan -> Text
$sel:memberArn:CreateChannelBan' :: CreateChannelBan -> Text
$sel:channelArn:CreateChannelBan' :: CreateChannelBan -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"MemberArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
memberArn)]
      )

instance Core.ToPath CreateChannelBan where
  toPath :: CreateChannelBan -> ByteString
toPath CreateChannelBan' {Text
chimeBearer :: Text
memberArn :: Text
channelArn :: Text
$sel:chimeBearer:CreateChannelBan' :: CreateChannelBan -> Text
$sel:memberArn:CreateChannelBan' :: CreateChannelBan -> Text
$sel:channelArn:CreateChannelBan' :: CreateChannelBan -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/channels/", Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
channelArn, ByteString
"/bans"]

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

-- | /See:/ 'newCreateChannelBanResponse' smart constructor.
data CreateChannelBanResponse = CreateChannelBanResponse'
  { -- | The ARN of the response to the ban request.
    CreateChannelBanResponse -> Maybe Text
channelArn :: Prelude.Maybe Prelude.Text,
    -- | The @ChannelArn@ and @BannedIdentity@ of the member in the ban response.
    CreateChannelBanResponse -> Maybe Identity
member :: Prelude.Maybe Identity,
    -- | The response's http status code.
    CreateChannelBanResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CreateChannelBanResponse -> CreateChannelBanResponse -> Bool
(CreateChannelBanResponse -> CreateChannelBanResponse -> Bool)
-> (CreateChannelBanResponse -> CreateChannelBanResponse -> Bool)
-> Eq CreateChannelBanResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateChannelBanResponse -> CreateChannelBanResponse -> Bool
$c/= :: CreateChannelBanResponse -> CreateChannelBanResponse -> Bool
== :: CreateChannelBanResponse -> CreateChannelBanResponse -> Bool
$c== :: CreateChannelBanResponse -> CreateChannelBanResponse -> Bool
Prelude.Eq, Int -> CreateChannelBanResponse -> ShowS
[CreateChannelBanResponse] -> ShowS
CreateChannelBanResponse -> String
(Int -> CreateChannelBanResponse -> ShowS)
-> (CreateChannelBanResponse -> String)
-> ([CreateChannelBanResponse] -> ShowS)
-> Show CreateChannelBanResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateChannelBanResponse] -> ShowS
$cshowList :: [CreateChannelBanResponse] -> ShowS
show :: CreateChannelBanResponse -> String
$cshow :: CreateChannelBanResponse -> String
showsPrec :: Int -> CreateChannelBanResponse -> ShowS
$cshowsPrec :: Int -> CreateChannelBanResponse -> ShowS
Prelude.Show, (forall x.
 CreateChannelBanResponse -> Rep CreateChannelBanResponse x)
-> (forall x.
    Rep CreateChannelBanResponse x -> CreateChannelBanResponse)
-> Generic CreateChannelBanResponse
forall x.
Rep CreateChannelBanResponse x -> CreateChannelBanResponse
forall x.
CreateChannelBanResponse -> Rep CreateChannelBanResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CreateChannelBanResponse x -> CreateChannelBanResponse
$cfrom :: forall x.
CreateChannelBanResponse -> Rep CreateChannelBanResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateChannelBanResponse' 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:
--
-- 'channelArn', 'createChannelBanResponse_channelArn' - The ARN of the response to the ban request.
--
-- 'member', 'createChannelBanResponse_member' - The @ChannelArn@ and @BannedIdentity@ of the member in the ban response.
--
-- 'httpStatus', 'createChannelBanResponse_httpStatus' - The response's http status code.
newCreateChannelBanResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateChannelBanResponse
newCreateChannelBanResponse :: Int -> CreateChannelBanResponse
newCreateChannelBanResponse Int
pHttpStatus_ =
  CreateChannelBanResponse' :: Maybe Text -> Maybe Identity -> Int -> CreateChannelBanResponse
CreateChannelBanResponse'
    { $sel:channelArn:CreateChannelBanResponse' :: Maybe Text
channelArn =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:member:CreateChannelBanResponse' :: Maybe Identity
member = Maybe Identity
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateChannelBanResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The ARN of the response to the ban request.
createChannelBanResponse_channelArn :: Lens.Lens' CreateChannelBanResponse (Prelude.Maybe Prelude.Text)
createChannelBanResponse_channelArn :: (Maybe Text -> f (Maybe Text))
-> CreateChannelBanResponse -> f CreateChannelBanResponse
createChannelBanResponse_channelArn = (CreateChannelBanResponse -> Maybe Text)
-> (CreateChannelBanResponse
    -> Maybe Text -> CreateChannelBanResponse)
-> Lens
     CreateChannelBanResponse
     CreateChannelBanResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateChannelBanResponse' {Maybe Text
channelArn :: Maybe Text
$sel:channelArn:CreateChannelBanResponse' :: CreateChannelBanResponse -> Maybe Text
channelArn} -> Maybe Text
channelArn) (\s :: CreateChannelBanResponse
s@CreateChannelBanResponse' {} Maybe Text
a -> CreateChannelBanResponse
s {$sel:channelArn:CreateChannelBanResponse' :: Maybe Text
channelArn = Maybe Text
a} :: CreateChannelBanResponse)

-- | The @ChannelArn@ and @BannedIdentity@ of the member in the ban response.
createChannelBanResponse_member :: Lens.Lens' CreateChannelBanResponse (Prelude.Maybe Identity)
createChannelBanResponse_member :: (Maybe Identity -> f (Maybe Identity))
-> CreateChannelBanResponse -> f CreateChannelBanResponse
createChannelBanResponse_member = (CreateChannelBanResponse -> Maybe Identity)
-> (CreateChannelBanResponse
    -> Maybe Identity -> CreateChannelBanResponse)
-> Lens
     CreateChannelBanResponse
     CreateChannelBanResponse
     (Maybe Identity)
     (Maybe Identity)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateChannelBanResponse' {Maybe Identity
member :: Maybe Identity
$sel:member:CreateChannelBanResponse' :: CreateChannelBanResponse -> Maybe Identity
member} -> Maybe Identity
member) (\s :: CreateChannelBanResponse
s@CreateChannelBanResponse' {} Maybe Identity
a -> CreateChannelBanResponse
s {$sel:member:CreateChannelBanResponse' :: Maybe Identity
member = Maybe Identity
a} :: CreateChannelBanResponse)

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

instance Prelude.NFData CreateChannelBanResponse