{-# 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.InviteUsers
-- 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)
--
-- Sends email to a maximum of 50 users, inviting them to the specified
-- Amazon Chime @Team@ account. Only @Team@ account types are currently
-- supported for this action.
module Amazonka.Chime.InviteUsers
  ( -- * Creating a Request
    InviteUsers (..),
    newInviteUsers,

    -- * Request Lenses
    inviteUsers_userType,
    inviteUsers_accountId,
    inviteUsers_userEmailList,

    -- * Destructuring the Response
    InviteUsersResponse (..),
    newInviteUsersResponse,

    -- * Response Lenses
    inviteUsersResponse_invites,
    inviteUsersResponse_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:/ 'newInviteUsers' smart constructor.
data InviteUsers = InviteUsers'
  { -- | The user type.
    InviteUsers -> Maybe UserType
userType :: Prelude.Maybe UserType,
    -- | The Amazon Chime account ID.
    InviteUsers -> Text
accountId :: Prelude.Text,
    -- | The user email addresses to which to send the email invitation.
    InviteUsers -> [Sensitive Text]
userEmailList :: [Core.Sensitive Prelude.Text]
  }
  deriving (InviteUsers -> InviteUsers -> Bool
(InviteUsers -> InviteUsers -> Bool)
-> (InviteUsers -> InviteUsers -> Bool) -> Eq InviteUsers
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: InviteUsers -> InviteUsers -> Bool
$c/= :: InviteUsers -> InviteUsers -> Bool
== :: InviteUsers -> InviteUsers -> Bool
$c== :: InviteUsers -> InviteUsers -> Bool
Prelude.Eq, Int -> InviteUsers -> ShowS
[InviteUsers] -> ShowS
InviteUsers -> String
(Int -> InviteUsers -> ShowS)
-> (InviteUsers -> String)
-> ([InviteUsers] -> ShowS)
-> Show InviteUsers
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InviteUsers] -> ShowS
$cshowList :: [InviteUsers] -> ShowS
show :: InviteUsers -> String
$cshow :: InviteUsers -> String
showsPrec :: Int -> InviteUsers -> ShowS
$cshowsPrec :: Int -> InviteUsers -> ShowS
Prelude.Show, (forall x. InviteUsers -> Rep InviteUsers x)
-> (forall x. Rep InviteUsers x -> InviteUsers)
-> Generic InviteUsers
forall x. Rep InviteUsers x -> InviteUsers
forall x. InviteUsers -> Rep InviteUsers x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep InviteUsers x -> InviteUsers
$cfrom :: forall x. InviteUsers -> Rep InviteUsers x
Prelude.Generic)

-- |
-- Create a value of 'InviteUsers' 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:
--
-- 'userType', 'inviteUsers_userType' - The user type.
--
-- 'accountId', 'inviteUsers_accountId' - The Amazon Chime account ID.
--
-- 'userEmailList', 'inviteUsers_userEmailList' - The user email addresses to which to send the email invitation.
newInviteUsers ::
  -- | 'accountId'
  Prelude.Text ->
  InviteUsers
newInviteUsers :: Text -> InviteUsers
newInviteUsers Text
pAccountId_ =
  InviteUsers' :: Maybe UserType -> Text -> [Sensitive Text] -> InviteUsers
InviteUsers'
    { $sel:userType:InviteUsers' :: Maybe UserType
userType = Maybe UserType
forall a. Maybe a
Prelude.Nothing,
      $sel:accountId:InviteUsers' :: Text
accountId = Text
pAccountId_,
      $sel:userEmailList:InviteUsers' :: [Sensitive Text]
userEmailList = [Sensitive Text]
forall a. Monoid a => a
Prelude.mempty
    }

-- | The user type.
inviteUsers_userType :: Lens.Lens' InviteUsers (Prelude.Maybe UserType)
inviteUsers_userType :: (Maybe UserType -> f (Maybe UserType))
-> InviteUsers -> f InviteUsers
inviteUsers_userType = (InviteUsers -> Maybe UserType)
-> (InviteUsers -> Maybe UserType -> InviteUsers)
-> Lens InviteUsers InviteUsers (Maybe UserType) (Maybe UserType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InviteUsers' {Maybe UserType
userType :: Maybe UserType
$sel:userType:InviteUsers' :: InviteUsers -> Maybe UserType
userType} -> Maybe UserType
userType) (\s :: InviteUsers
s@InviteUsers' {} Maybe UserType
a -> InviteUsers
s {$sel:userType:InviteUsers' :: Maybe UserType
userType = Maybe UserType
a} :: InviteUsers)

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

-- | The user email addresses to which to send the email invitation.
inviteUsers_userEmailList :: Lens.Lens' InviteUsers [Prelude.Text]
inviteUsers_userEmailList :: ([Text] -> f [Text]) -> InviteUsers -> f InviteUsers
inviteUsers_userEmailList = (InviteUsers -> [Sensitive Text])
-> (InviteUsers -> [Sensitive Text] -> InviteUsers)
-> Lens InviteUsers InviteUsers [Sensitive Text] [Sensitive Text]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InviteUsers' {[Sensitive Text]
userEmailList :: [Sensitive Text]
$sel:userEmailList:InviteUsers' :: InviteUsers -> [Sensitive Text]
userEmailList} -> [Sensitive Text]
userEmailList) (\s :: InviteUsers
s@InviteUsers' {} [Sensitive Text]
a -> InviteUsers
s {$sel:userEmailList:InviteUsers' :: [Sensitive Text]
userEmailList = [Sensitive Text]
a} :: InviteUsers) (([Sensitive Text] -> f [Sensitive Text])
 -> InviteUsers -> f InviteUsers)
-> (([Text] -> f [Text]) -> [Sensitive Text] -> f [Sensitive Text])
-> ([Text] -> f [Text])
-> InviteUsers
-> f InviteUsers
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Text] -> f [Text]) -> [Sensitive Text] -> f [Sensitive Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData InviteUsers

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

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

instance Core.ToPath InviteUsers where
  toPath :: InviteUsers -> ByteString
toPath InviteUsers' {[Sensitive Text]
Maybe UserType
Text
userEmailList :: [Sensitive Text]
accountId :: Text
userType :: Maybe UserType
$sel:userEmailList:InviteUsers' :: InviteUsers -> [Sensitive Text]
$sel:accountId:InviteUsers' :: InviteUsers -> Text
$sel:userType:InviteUsers' :: InviteUsers -> Maybe UserType
..} =
    [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
"/users"]

instance Core.ToQuery InviteUsers where
  toQuery :: InviteUsers -> QueryString
toQuery =
    QueryString -> InviteUsers -> QueryString
forall a b. a -> b -> a
Prelude.const ([QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat [QueryString
"operation=add"])

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

-- |
-- Create a value of 'InviteUsersResponse' 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:
--
-- 'invites', 'inviteUsersResponse_invites' - The email invitation details.
--
-- 'httpStatus', 'inviteUsersResponse_httpStatus' - The response's http status code.
newInviteUsersResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  InviteUsersResponse
newInviteUsersResponse :: Int -> InviteUsersResponse
newInviteUsersResponse Int
pHttpStatus_ =
  InviteUsersResponse' :: Maybe [Invite] -> Int -> InviteUsersResponse
InviteUsersResponse'
    { $sel:invites:InviteUsersResponse' :: Maybe [Invite]
invites = Maybe [Invite]
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:InviteUsersResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The email invitation details.
inviteUsersResponse_invites :: Lens.Lens' InviteUsersResponse (Prelude.Maybe [Invite])
inviteUsersResponse_invites :: (Maybe [Invite] -> f (Maybe [Invite]))
-> InviteUsersResponse -> f InviteUsersResponse
inviteUsersResponse_invites = (InviteUsersResponse -> Maybe [Invite])
-> (InviteUsersResponse -> Maybe [Invite] -> InviteUsersResponse)
-> Lens
     InviteUsersResponse
     InviteUsersResponse
     (Maybe [Invite])
     (Maybe [Invite])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InviteUsersResponse' {Maybe [Invite]
invites :: Maybe [Invite]
$sel:invites:InviteUsersResponse' :: InviteUsersResponse -> Maybe [Invite]
invites} -> Maybe [Invite]
invites) (\s :: InviteUsersResponse
s@InviteUsersResponse' {} Maybe [Invite]
a -> InviteUsersResponse
s {$sel:invites:InviteUsersResponse' :: Maybe [Invite]
invites = Maybe [Invite]
a} :: InviteUsersResponse) ((Maybe [Invite] -> f (Maybe [Invite]))
 -> InviteUsersResponse -> f InviteUsersResponse)
-> ((Maybe [Invite] -> f (Maybe [Invite]))
    -> Maybe [Invite] -> f (Maybe [Invite]))
-> (Maybe [Invite] -> f (Maybe [Invite]))
-> InviteUsersResponse
-> f InviteUsersResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Invite] [Invite] [Invite] [Invite]
-> Iso
     (Maybe [Invite]) (Maybe [Invite]) (Maybe [Invite]) (Maybe [Invite])
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 [Invite] [Invite] [Invite] [Invite]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData InviteUsersResponse