{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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 :: [Data.Sensitive Prelude.Text]
  }
  deriving (InviteUsers -> InviteUsers -> Bool
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
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. 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'
    { $sel:userType:InviteUsers' :: Maybe UserType
userType = forall a. Maybe a
Prelude.Nothing,
      $sel:accountId:InviteUsers' :: Text
accountId = Text
pAccountId_,
      $sel:userEmailList:InviteUsers' :: [Sensitive Text]
userEmailList = forall a. Monoid a => a
Prelude.mempty
    }

-- | The user type.
inviteUsers_userType :: Lens.Lens' InviteUsers (Prelude.Maybe UserType)
inviteUsers_userType :: Lens' InviteUsers (Maybe UserType)
inviteUsers_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 :: Lens' InviteUsers Text
inviteUsers_accountId = 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 :: Lens' InviteUsers [Text]
inviteUsers_userEmailList = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 :: (Service -> Service) -> InviteUsers -> Request InviteUsers
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy InviteUsers
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse InviteUsers)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe [Invite] -> Int -> InviteUsersResponse
InviteUsersResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"Invites" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable InviteUsers where
  hashWithSalt :: Int -> InviteUsers -> Int
hashWithSalt Int
_salt 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
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe UserType
userType
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
accountId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [Sensitive Text]
userEmailList

instance Prelude.NFData InviteUsers where
  rnf :: InviteUsers -> ()
rnf 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
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe UserType
userType
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
accountId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [Sensitive Text]
userEmailList

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

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"UserType" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe UserType
userType,
            forall a. a -> Maybe a
Prelude.Just
              (Key
"UserEmailList" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= [Sensitive Text]
userEmailList)
          ]
      )

instance Data.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
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/accounts/", forall a. ToByteString a => a -> ByteString
Data.toBS Text
accountId, ByteString
"/users"]

instance Data.ToQuery InviteUsers where
  toQuery :: InviteUsers -> QueryString
toQuery =
    forall a b. a -> b -> a
Prelude.const (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
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
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. 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'
    { $sel:invites:InviteUsersResponse' :: Maybe [Invite]
invites = 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 :: Lens' InviteUsersResponse (Maybe [Invite])
inviteUsersResponse_invites = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 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 :: Lens' InviteUsersResponse Int
inviteUsersResponse_httpStatus = 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 where
  rnf :: InviteUsersResponse -> ()
rnf InviteUsersResponse' {Int
Maybe [Invite]
httpStatus :: Int
invites :: Maybe [Invite]
$sel:httpStatus:InviteUsersResponse' :: InviteUsersResponse -> Int
$sel:invites:InviteUsersResponse' :: InviteUsersResponse -> Maybe [Invite]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Invite]
invites
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus