{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.IoTEvents.Types.EmailRecipients
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.IoTEvents.Types.EmailRecipients where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.IoTEvents.Types.RecipientDetail
import qualified Amazonka.Prelude as Prelude

-- | Contains the information of one or more recipients who receive the
-- emails.
--
-- You must
-- <https://docs.aws.amazon.com/singlesignon/latest/userguide/addusers.html add the users that receive emails to your AWS SSO store>.
--
-- /See:/ 'newEmailRecipients' smart constructor.
data EmailRecipients = EmailRecipients'
  { -- | Specifies one or more recipients who receive the email.
    EmailRecipients -> Maybe (NonEmpty RecipientDetail)
to :: Prelude.Maybe (Prelude.NonEmpty RecipientDetail)
  }
  deriving (EmailRecipients -> EmailRecipients -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EmailRecipients -> EmailRecipients -> Bool
$c/= :: EmailRecipients -> EmailRecipients -> Bool
== :: EmailRecipients -> EmailRecipients -> Bool
$c== :: EmailRecipients -> EmailRecipients -> Bool
Prelude.Eq, ReadPrec [EmailRecipients]
ReadPrec EmailRecipients
Int -> ReadS EmailRecipients
ReadS [EmailRecipients]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EmailRecipients]
$creadListPrec :: ReadPrec [EmailRecipients]
readPrec :: ReadPrec EmailRecipients
$creadPrec :: ReadPrec EmailRecipients
readList :: ReadS [EmailRecipients]
$creadList :: ReadS [EmailRecipients]
readsPrec :: Int -> ReadS EmailRecipients
$creadsPrec :: Int -> ReadS EmailRecipients
Prelude.Read, Int -> EmailRecipients -> ShowS
[EmailRecipients] -> ShowS
EmailRecipients -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EmailRecipients] -> ShowS
$cshowList :: [EmailRecipients] -> ShowS
show :: EmailRecipients -> String
$cshow :: EmailRecipients -> String
showsPrec :: Int -> EmailRecipients -> ShowS
$cshowsPrec :: Int -> EmailRecipients -> ShowS
Prelude.Show, forall x. Rep EmailRecipients x -> EmailRecipients
forall x. EmailRecipients -> Rep EmailRecipients x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep EmailRecipients x -> EmailRecipients
$cfrom :: forall x. EmailRecipients -> Rep EmailRecipients x
Prelude.Generic)

-- |
-- Create a value of 'EmailRecipients' 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:
--
-- 'to', 'emailRecipients_to' - Specifies one or more recipients who receive the email.
newEmailRecipients ::
  EmailRecipients
newEmailRecipients :: EmailRecipients
newEmailRecipients =
  EmailRecipients' {$sel:to:EmailRecipients' :: Maybe (NonEmpty RecipientDetail)
to = forall a. Maybe a
Prelude.Nothing}

-- | Specifies one or more recipients who receive the email.
emailRecipients_to :: Lens.Lens' EmailRecipients (Prelude.Maybe (Prelude.NonEmpty RecipientDetail))
emailRecipients_to :: Lens' EmailRecipients (Maybe (NonEmpty RecipientDetail))
emailRecipients_to = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EmailRecipients' {Maybe (NonEmpty RecipientDetail)
to :: Maybe (NonEmpty RecipientDetail)
$sel:to:EmailRecipients' :: EmailRecipients -> Maybe (NonEmpty RecipientDetail)
to} -> Maybe (NonEmpty RecipientDetail)
to) (\s :: EmailRecipients
s@EmailRecipients' {} Maybe (NonEmpty RecipientDetail)
a -> EmailRecipients
s {$sel:to:EmailRecipients' :: Maybe (NonEmpty RecipientDetail)
to = Maybe (NonEmpty RecipientDetail)
a} :: EmailRecipients) 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

instance Data.FromJSON EmailRecipients where
  parseJSON :: Value -> Parser EmailRecipients
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"EmailRecipients"
      ( \Object
x ->
          Maybe (NonEmpty RecipientDetail) -> EmailRecipients
EmailRecipients' forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"to")
      )

instance Prelude.Hashable EmailRecipients where
  hashWithSalt :: Int -> EmailRecipients -> Int
hashWithSalt Int
_salt EmailRecipients' {Maybe (NonEmpty RecipientDetail)
to :: Maybe (NonEmpty RecipientDetail)
$sel:to:EmailRecipients' :: EmailRecipients -> Maybe (NonEmpty RecipientDetail)
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (NonEmpty RecipientDetail)
to

instance Prelude.NFData EmailRecipients where
  rnf :: EmailRecipients -> ()
rnf EmailRecipients' {Maybe (NonEmpty RecipientDetail)
to :: Maybe (NonEmpty RecipientDetail)
$sel:to:EmailRecipients' :: EmailRecipients -> Maybe (NonEmpty RecipientDetail)
..} = forall a. NFData a => a -> ()
Prelude.rnf Maybe (NonEmpty RecipientDetail)
to

instance Data.ToJSON EmailRecipients where
  toJSON :: EmailRecipients -> Value
toJSON EmailRecipients' {Maybe (NonEmpty RecipientDetail)
to :: Maybe (NonEmpty RecipientDetail)
$sel:to:EmailRecipients' :: EmailRecipients -> Maybe (NonEmpty RecipientDetail)
..} =
    [Pair] -> Value
Data.object
      (forall a. [Maybe a] -> [a]
Prelude.catMaybes [(Key
"to" 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 (NonEmpty RecipientDetail)
to])