{-# 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.CreateRoomMembership
-- 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)
--
-- Adds a member to a chat room in an Amazon Chime Enterprise account. A
-- member can be either a user or a bot. The member role designates whether
-- the member is a chat room administrator or a general chat room member.
module Amazonka.Chime.CreateRoomMembership
  ( -- * Creating a Request
    CreateRoomMembership (..),
    newCreateRoomMembership,

    -- * Request Lenses
    createRoomMembership_role,
    createRoomMembership_accountId,
    createRoomMembership_roomId,
    createRoomMembership_memberId,

    -- * Destructuring the Response
    CreateRoomMembershipResponse (..),
    newCreateRoomMembershipResponse,

    -- * Response Lenses
    createRoomMembershipResponse_roomMembership,
    createRoomMembershipResponse_httpStatus,
  )
where

import Amazonka.Chime.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:/ 'newCreateRoomMembership' smart constructor.
data CreateRoomMembership = CreateRoomMembership'
  { -- | The role of the member.
    CreateRoomMembership -> Maybe RoomMembershipRole
role' :: Prelude.Maybe RoomMembershipRole,
    -- | The Amazon Chime account ID.
    CreateRoomMembership -> Text
accountId :: Prelude.Text,
    -- | The room ID.
    CreateRoomMembership -> Text
roomId :: Prelude.Text,
    -- | The Amazon Chime member ID (user ID or bot ID).
    CreateRoomMembership -> Text
memberId :: Prelude.Text
  }
  deriving (CreateRoomMembership -> CreateRoomMembership -> Bool
(CreateRoomMembership -> CreateRoomMembership -> Bool)
-> (CreateRoomMembership -> CreateRoomMembership -> Bool)
-> Eq CreateRoomMembership
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateRoomMembership -> CreateRoomMembership -> Bool
$c/= :: CreateRoomMembership -> CreateRoomMembership -> Bool
== :: CreateRoomMembership -> CreateRoomMembership -> Bool
$c== :: CreateRoomMembership -> CreateRoomMembership -> Bool
Prelude.Eq, ReadPrec [CreateRoomMembership]
ReadPrec CreateRoomMembership
Int -> ReadS CreateRoomMembership
ReadS [CreateRoomMembership]
(Int -> ReadS CreateRoomMembership)
-> ReadS [CreateRoomMembership]
-> ReadPrec CreateRoomMembership
-> ReadPrec [CreateRoomMembership]
-> Read CreateRoomMembership
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateRoomMembership]
$creadListPrec :: ReadPrec [CreateRoomMembership]
readPrec :: ReadPrec CreateRoomMembership
$creadPrec :: ReadPrec CreateRoomMembership
readList :: ReadS [CreateRoomMembership]
$creadList :: ReadS [CreateRoomMembership]
readsPrec :: Int -> ReadS CreateRoomMembership
$creadsPrec :: Int -> ReadS CreateRoomMembership
Prelude.Read, Int -> CreateRoomMembership -> ShowS
[CreateRoomMembership] -> ShowS
CreateRoomMembership -> String
(Int -> CreateRoomMembership -> ShowS)
-> (CreateRoomMembership -> String)
-> ([CreateRoomMembership] -> ShowS)
-> Show CreateRoomMembership
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateRoomMembership] -> ShowS
$cshowList :: [CreateRoomMembership] -> ShowS
show :: CreateRoomMembership -> String
$cshow :: CreateRoomMembership -> String
showsPrec :: Int -> CreateRoomMembership -> ShowS
$cshowsPrec :: Int -> CreateRoomMembership -> ShowS
Prelude.Show, (forall x. CreateRoomMembership -> Rep CreateRoomMembership x)
-> (forall x. Rep CreateRoomMembership x -> CreateRoomMembership)
-> Generic CreateRoomMembership
forall x. Rep CreateRoomMembership x -> CreateRoomMembership
forall x. CreateRoomMembership -> Rep CreateRoomMembership x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateRoomMembership x -> CreateRoomMembership
$cfrom :: forall x. CreateRoomMembership -> Rep CreateRoomMembership x
Prelude.Generic)

-- |
-- Create a value of 'CreateRoomMembership' 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:
--
-- 'role'', 'createRoomMembership_role' - The role of the member.
--
-- 'accountId', 'createRoomMembership_accountId' - The Amazon Chime account ID.
--
-- 'roomId', 'createRoomMembership_roomId' - The room ID.
--
-- 'memberId', 'createRoomMembership_memberId' - The Amazon Chime member ID (user ID or bot ID).
newCreateRoomMembership ::
  -- | 'accountId'
  Prelude.Text ->
  -- | 'roomId'
  Prelude.Text ->
  -- | 'memberId'
  Prelude.Text ->
  CreateRoomMembership
newCreateRoomMembership :: Text -> Text -> Text -> CreateRoomMembership
newCreateRoomMembership
  Text
pAccountId_
  Text
pRoomId_
  Text
pMemberId_ =
    CreateRoomMembership' :: Maybe RoomMembershipRole
-> Text -> Text -> Text -> CreateRoomMembership
CreateRoomMembership'
      { $sel:role':CreateRoomMembership' :: Maybe RoomMembershipRole
role' = Maybe RoomMembershipRole
forall a. Maybe a
Prelude.Nothing,
        $sel:accountId:CreateRoomMembership' :: Text
accountId = Text
pAccountId_,
        $sel:roomId:CreateRoomMembership' :: Text
roomId = Text
pRoomId_,
        $sel:memberId:CreateRoomMembership' :: Text
memberId = Text
pMemberId_
      }

-- | The role of the member.
createRoomMembership_role :: Lens.Lens' CreateRoomMembership (Prelude.Maybe RoomMembershipRole)
createRoomMembership_role :: (Maybe RoomMembershipRole -> f (Maybe RoomMembershipRole))
-> CreateRoomMembership -> f CreateRoomMembership
createRoomMembership_role = (CreateRoomMembership -> Maybe RoomMembershipRole)
-> (CreateRoomMembership
    -> Maybe RoomMembershipRole -> CreateRoomMembership)
-> Lens
     CreateRoomMembership
     CreateRoomMembership
     (Maybe RoomMembershipRole)
     (Maybe RoomMembershipRole)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateRoomMembership' {Maybe RoomMembershipRole
role' :: Maybe RoomMembershipRole
$sel:role':CreateRoomMembership' :: CreateRoomMembership -> Maybe RoomMembershipRole
role'} -> Maybe RoomMembershipRole
role') (\s :: CreateRoomMembership
s@CreateRoomMembership' {} Maybe RoomMembershipRole
a -> CreateRoomMembership
s {$sel:role':CreateRoomMembership' :: Maybe RoomMembershipRole
role' = Maybe RoomMembershipRole
a} :: CreateRoomMembership)

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

-- | The room ID.
createRoomMembership_roomId :: Lens.Lens' CreateRoomMembership Prelude.Text
createRoomMembership_roomId :: (Text -> f Text) -> CreateRoomMembership -> f CreateRoomMembership
createRoomMembership_roomId = (CreateRoomMembership -> Text)
-> (CreateRoomMembership -> Text -> CreateRoomMembership)
-> Lens CreateRoomMembership CreateRoomMembership Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateRoomMembership' {Text
roomId :: Text
$sel:roomId:CreateRoomMembership' :: CreateRoomMembership -> Text
roomId} -> Text
roomId) (\s :: CreateRoomMembership
s@CreateRoomMembership' {} Text
a -> CreateRoomMembership
s {$sel:roomId:CreateRoomMembership' :: Text
roomId = Text
a} :: CreateRoomMembership)

-- | The Amazon Chime member ID (user ID or bot ID).
createRoomMembership_memberId :: Lens.Lens' CreateRoomMembership Prelude.Text
createRoomMembership_memberId :: (Text -> f Text) -> CreateRoomMembership -> f CreateRoomMembership
createRoomMembership_memberId = (CreateRoomMembership -> Text)
-> (CreateRoomMembership -> Text -> CreateRoomMembership)
-> Lens CreateRoomMembership CreateRoomMembership Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateRoomMembership' {Text
memberId :: Text
$sel:memberId:CreateRoomMembership' :: CreateRoomMembership -> Text
memberId} -> Text
memberId) (\s :: CreateRoomMembership
s@CreateRoomMembership' {} Text
a -> CreateRoomMembership
s {$sel:memberId:CreateRoomMembership' :: Text
memberId = Text
a} :: CreateRoomMembership)

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

instance Prelude.NFData CreateRoomMembership

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

instance Core.ToJSON CreateRoomMembership where
  toJSON :: CreateRoomMembership -> Value
toJSON CreateRoomMembership' {Maybe RoomMembershipRole
Text
memberId :: Text
roomId :: Text
accountId :: Text
role' :: Maybe RoomMembershipRole
$sel:memberId:CreateRoomMembership' :: CreateRoomMembership -> Text
$sel:roomId:CreateRoomMembership' :: CreateRoomMembership -> Text
$sel:accountId:CreateRoomMembership' :: CreateRoomMembership -> Text
$sel:role':CreateRoomMembership' :: CreateRoomMembership -> Maybe RoomMembershipRole
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Role" Text -> RoomMembershipRole -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (RoomMembershipRole -> Pair)
-> Maybe RoomMembershipRole -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe RoomMembershipRole
role',
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"MemberId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
memberId)
          ]
      )

instance Core.ToPath CreateRoomMembership where
  toPath :: CreateRoomMembership -> ByteString
toPath CreateRoomMembership' {Maybe RoomMembershipRole
Text
memberId :: Text
roomId :: Text
accountId :: Text
role' :: Maybe RoomMembershipRole
$sel:memberId:CreateRoomMembership' :: CreateRoomMembership -> Text
$sel:roomId:CreateRoomMembership' :: CreateRoomMembership -> Text
$sel:accountId:CreateRoomMembership' :: CreateRoomMembership -> Text
$sel:role':CreateRoomMembership' :: CreateRoomMembership -> Maybe RoomMembershipRole
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/accounts/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
accountId,
        ByteString
"/rooms/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
roomId,
        ByteString
"/memberships"
      ]

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

-- | /See:/ 'newCreateRoomMembershipResponse' smart constructor.
data CreateRoomMembershipResponse = CreateRoomMembershipResponse'
  { -- | The room membership details.
    CreateRoomMembershipResponse -> Maybe RoomMembership
roomMembership :: Prelude.Maybe RoomMembership,
    -- | The response's http status code.
    CreateRoomMembershipResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CreateRoomMembershipResponse
-> CreateRoomMembershipResponse -> Bool
(CreateRoomMembershipResponse
 -> CreateRoomMembershipResponse -> Bool)
-> (CreateRoomMembershipResponse
    -> CreateRoomMembershipResponse -> Bool)
-> Eq CreateRoomMembershipResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateRoomMembershipResponse
-> CreateRoomMembershipResponse -> Bool
$c/= :: CreateRoomMembershipResponse
-> CreateRoomMembershipResponse -> Bool
== :: CreateRoomMembershipResponse
-> CreateRoomMembershipResponse -> Bool
$c== :: CreateRoomMembershipResponse
-> CreateRoomMembershipResponse -> Bool
Prelude.Eq, Int -> CreateRoomMembershipResponse -> ShowS
[CreateRoomMembershipResponse] -> ShowS
CreateRoomMembershipResponse -> String
(Int -> CreateRoomMembershipResponse -> ShowS)
-> (CreateRoomMembershipResponse -> String)
-> ([CreateRoomMembershipResponse] -> ShowS)
-> Show CreateRoomMembershipResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateRoomMembershipResponse] -> ShowS
$cshowList :: [CreateRoomMembershipResponse] -> ShowS
show :: CreateRoomMembershipResponse -> String
$cshow :: CreateRoomMembershipResponse -> String
showsPrec :: Int -> CreateRoomMembershipResponse -> ShowS
$cshowsPrec :: Int -> CreateRoomMembershipResponse -> ShowS
Prelude.Show, (forall x.
 CreateRoomMembershipResponse -> Rep CreateRoomMembershipResponse x)
-> (forall x.
    Rep CreateRoomMembershipResponse x -> CreateRoomMembershipResponse)
-> Generic CreateRoomMembershipResponse
forall x.
Rep CreateRoomMembershipResponse x -> CreateRoomMembershipResponse
forall x.
CreateRoomMembershipResponse -> Rep CreateRoomMembershipResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CreateRoomMembershipResponse x -> CreateRoomMembershipResponse
$cfrom :: forall x.
CreateRoomMembershipResponse -> Rep CreateRoomMembershipResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateRoomMembershipResponse' 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:
--
-- 'roomMembership', 'createRoomMembershipResponse_roomMembership' - The room membership details.
--
-- 'httpStatus', 'createRoomMembershipResponse_httpStatus' - The response's http status code.
newCreateRoomMembershipResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateRoomMembershipResponse
newCreateRoomMembershipResponse :: Int -> CreateRoomMembershipResponse
newCreateRoomMembershipResponse Int
pHttpStatus_ =
  CreateRoomMembershipResponse' :: Maybe RoomMembership -> Int -> CreateRoomMembershipResponse
CreateRoomMembershipResponse'
    { $sel:roomMembership:CreateRoomMembershipResponse' :: Maybe RoomMembership
roomMembership =
        Maybe RoomMembership
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateRoomMembershipResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The room membership details.
createRoomMembershipResponse_roomMembership :: Lens.Lens' CreateRoomMembershipResponse (Prelude.Maybe RoomMembership)
createRoomMembershipResponse_roomMembership :: (Maybe RoomMembership -> f (Maybe RoomMembership))
-> CreateRoomMembershipResponse -> f CreateRoomMembershipResponse
createRoomMembershipResponse_roomMembership = (CreateRoomMembershipResponse -> Maybe RoomMembership)
-> (CreateRoomMembershipResponse
    -> Maybe RoomMembership -> CreateRoomMembershipResponse)
-> Lens
     CreateRoomMembershipResponse
     CreateRoomMembershipResponse
     (Maybe RoomMembership)
     (Maybe RoomMembership)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateRoomMembershipResponse' {Maybe RoomMembership
roomMembership :: Maybe RoomMembership
$sel:roomMembership:CreateRoomMembershipResponse' :: CreateRoomMembershipResponse -> Maybe RoomMembership
roomMembership} -> Maybe RoomMembership
roomMembership) (\s :: CreateRoomMembershipResponse
s@CreateRoomMembershipResponse' {} Maybe RoomMembership
a -> CreateRoomMembershipResponse
s {$sel:roomMembership:CreateRoomMembershipResponse' :: Maybe RoomMembership
roomMembership = Maybe RoomMembership
a} :: CreateRoomMembershipResponse)

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

instance Prelude.NFData CreateRoomMembershipResponse