{-# 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.CreateRoom
-- 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)
--
-- Creates a chat room for the specified Amazon Chime Enterprise account.
module Amazonka.Chime.CreateRoom
  ( -- * Creating a Request
    CreateRoom (..),
    newCreateRoom,

    -- * Request Lenses
    createRoom_clientRequestToken,
    createRoom_accountId,
    createRoom_name,

    -- * Destructuring the Response
    CreateRoomResponse (..),
    newCreateRoomResponse,

    -- * Response Lenses
    createRoomResponse_room,
    createRoomResponse_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:/ 'newCreateRoom' smart constructor.
data CreateRoom = CreateRoom'
  { -- | The idempotency token for the request.
    CreateRoom -> Maybe (Sensitive Text)
clientRequestToken :: Prelude.Maybe (Core.Sensitive Prelude.Text),
    -- | The Amazon Chime account ID.
    CreateRoom -> Text
accountId :: Prelude.Text,
    -- | The room name.
    CreateRoom -> Sensitive Text
name :: Core.Sensitive Prelude.Text
  }
  deriving (CreateRoom -> CreateRoom -> Bool
(CreateRoom -> CreateRoom -> Bool)
-> (CreateRoom -> CreateRoom -> Bool) -> Eq CreateRoom
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateRoom -> CreateRoom -> Bool
$c/= :: CreateRoom -> CreateRoom -> Bool
== :: CreateRoom -> CreateRoom -> Bool
$c== :: CreateRoom -> CreateRoom -> Bool
Prelude.Eq, Int -> CreateRoom -> ShowS
[CreateRoom] -> ShowS
CreateRoom -> String
(Int -> CreateRoom -> ShowS)
-> (CreateRoom -> String)
-> ([CreateRoom] -> ShowS)
-> Show CreateRoom
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateRoom] -> ShowS
$cshowList :: [CreateRoom] -> ShowS
show :: CreateRoom -> String
$cshow :: CreateRoom -> String
showsPrec :: Int -> CreateRoom -> ShowS
$cshowsPrec :: Int -> CreateRoom -> ShowS
Prelude.Show, (forall x. CreateRoom -> Rep CreateRoom x)
-> (forall x. Rep CreateRoom x -> CreateRoom) -> Generic CreateRoom
forall x. Rep CreateRoom x -> CreateRoom
forall x. CreateRoom -> Rep CreateRoom x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateRoom x -> CreateRoom
$cfrom :: forall x. CreateRoom -> Rep CreateRoom x
Prelude.Generic)

-- |
-- Create a value of 'CreateRoom' 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:
--
-- 'clientRequestToken', 'createRoom_clientRequestToken' - The idempotency token for the request.
--
-- 'accountId', 'createRoom_accountId' - The Amazon Chime account ID.
--
-- 'name', 'createRoom_name' - The room name.
newCreateRoom ::
  -- | 'accountId'
  Prelude.Text ->
  -- | 'name'
  Prelude.Text ->
  CreateRoom
newCreateRoom :: Text -> Text -> CreateRoom
newCreateRoom Text
pAccountId_ Text
pName_ =
  CreateRoom' :: Maybe (Sensitive Text) -> Text -> Sensitive Text -> CreateRoom
CreateRoom'
    { $sel:clientRequestToken:CreateRoom' :: Maybe (Sensitive Text)
clientRequestToken = Maybe (Sensitive Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:accountId:CreateRoom' :: Text
accountId = Text
pAccountId_,
      $sel:name:CreateRoom' :: Sensitive Text
name = Tagged Text (Identity Text)
-> Tagged (Sensitive Text) (Identity (Sensitive Text))
forall a. Iso' (Sensitive a) a
Core._Sensitive (Tagged Text (Identity Text)
 -> Tagged (Sensitive Text) (Identity (Sensitive Text)))
-> Text -> Sensitive Text
forall t b. AReview t b -> b -> t
Lens.# Text
pName_
    }

-- | The idempotency token for the request.
createRoom_clientRequestToken :: Lens.Lens' CreateRoom (Prelude.Maybe Prelude.Text)
createRoom_clientRequestToken :: (Maybe Text -> f (Maybe Text)) -> CreateRoom -> f CreateRoom
createRoom_clientRequestToken = (CreateRoom -> Maybe (Sensitive Text))
-> (CreateRoom -> Maybe (Sensitive Text) -> CreateRoom)
-> Lens
     CreateRoom
     CreateRoom
     (Maybe (Sensitive Text))
     (Maybe (Sensitive Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateRoom' {Maybe (Sensitive Text)
clientRequestToken :: Maybe (Sensitive Text)
$sel:clientRequestToken:CreateRoom' :: CreateRoom -> Maybe (Sensitive Text)
clientRequestToken} -> Maybe (Sensitive Text)
clientRequestToken) (\s :: CreateRoom
s@CreateRoom' {} Maybe (Sensitive Text)
a -> CreateRoom
s {$sel:clientRequestToken:CreateRoom' :: Maybe (Sensitive Text)
clientRequestToken = Maybe (Sensitive Text)
a} :: CreateRoom) ((Maybe (Sensitive Text) -> f (Maybe (Sensitive Text)))
 -> CreateRoom -> f CreateRoom)
-> ((Maybe Text -> f (Maybe Text))
    -> Maybe (Sensitive Text) -> f (Maybe (Sensitive Text)))
-> (Maybe Text -> f (Maybe Text))
-> CreateRoom
-> f CreateRoom
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso (Sensitive Text) (Sensitive Text) Text Text
-> Iso
     (Maybe (Sensitive Text))
     (Maybe (Sensitive Text))
     (Maybe Text)
     (Maybe 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 (Sensitive Text) (Sensitive Text) Text Text
forall a. Iso' (Sensitive a) a
Core._Sensitive

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

-- | The room name.
createRoom_name :: Lens.Lens' CreateRoom Prelude.Text
createRoom_name :: (Text -> f Text) -> CreateRoom -> f CreateRoom
createRoom_name = (CreateRoom -> Sensitive Text)
-> (CreateRoom -> Sensitive Text -> CreateRoom)
-> Lens CreateRoom CreateRoom (Sensitive Text) (Sensitive Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateRoom' {Sensitive Text
name :: Sensitive Text
$sel:name:CreateRoom' :: CreateRoom -> Sensitive Text
name} -> Sensitive Text
name) (\s :: CreateRoom
s@CreateRoom' {} Sensitive Text
a -> CreateRoom
s {$sel:name:CreateRoom' :: Sensitive Text
name = Sensitive Text
a} :: CreateRoom) ((Sensitive Text -> f (Sensitive Text))
 -> CreateRoom -> f CreateRoom)
-> ((Text -> f Text) -> Sensitive Text -> f (Sensitive Text))
-> (Text -> f Text)
-> CreateRoom
-> f CreateRoom
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (Text -> f Text) -> Sensitive Text -> f (Sensitive Text)
forall a. Iso' (Sensitive a) a
Core._Sensitive

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

instance Prelude.NFData CreateRoom

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

instance Core.ToJSON CreateRoom where
  toJSON :: CreateRoom -> Value
toJSON CreateRoom' {Maybe (Sensitive Text)
Text
Sensitive Text
name :: Sensitive Text
accountId :: Text
clientRequestToken :: Maybe (Sensitive Text)
$sel:name:CreateRoom' :: CreateRoom -> Sensitive Text
$sel:accountId:CreateRoom' :: CreateRoom -> Text
$sel:clientRequestToken:CreateRoom' :: CreateRoom -> Maybe (Sensitive Text)
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"ClientRequestToken" Text -> Sensitive Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Sensitive Text -> Pair) -> Maybe (Sensitive Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (Sensitive Text)
clientRequestToken,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Name" Text -> Sensitive Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Sensitive Text
name)
          ]
      )

instance Core.ToPath CreateRoom where
  toPath :: CreateRoom -> ByteString
toPath CreateRoom' {Maybe (Sensitive Text)
Text
Sensitive Text
name :: Sensitive Text
accountId :: Text
clientRequestToken :: Maybe (Sensitive Text)
$sel:name:CreateRoom' :: CreateRoom -> Sensitive Text
$sel:accountId:CreateRoom' :: CreateRoom -> Text
$sel:clientRequestToken:CreateRoom' :: CreateRoom -> Maybe (Sensitive Text)
..} =
    [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"]

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

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

-- |
-- Create a value of 'CreateRoomResponse' 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:
--
-- 'room', 'createRoomResponse_room' - The room details.
--
-- 'httpStatus', 'createRoomResponse_httpStatus' - The response's http status code.
newCreateRoomResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateRoomResponse
newCreateRoomResponse :: Int -> CreateRoomResponse
newCreateRoomResponse Int
pHttpStatus_ =
  CreateRoomResponse' :: Maybe Room -> Int -> CreateRoomResponse
CreateRoomResponse'
    { $sel:room:CreateRoomResponse' :: Maybe Room
room = Maybe Room
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateRoomResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The room details.
createRoomResponse_room :: Lens.Lens' CreateRoomResponse (Prelude.Maybe Room)
createRoomResponse_room :: (Maybe Room -> f (Maybe Room))
-> CreateRoomResponse -> f CreateRoomResponse
createRoomResponse_room = (CreateRoomResponse -> Maybe Room)
-> (CreateRoomResponse -> Maybe Room -> CreateRoomResponse)
-> Lens
     CreateRoomResponse CreateRoomResponse (Maybe Room) (Maybe Room)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateRoomResponse' {Maybe Room
room :: Maybe Room
$sel:room:CreateRoomResponse' :: CreateRoomResponse -> Maybe Room
room} -> Maybe Room
room) (\s :: CreateRoomResponse
s@CreateRoomResponse' {} Maybe Room
a -> CreateRoomResponse
s {$sel:room:CreateRoomResponse' :: Maybe Room
room = Maybe Room
a} :: CreateRoomResponse)

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

instance Prelude.NFData CreateRoomResponse