{-# 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-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)
module Amazonka.IoTEvents.Types.EmailRecipients where

import qualified Amazonka.Core as Core
import Amazonka.IoTEvents.Types.RecipientDetail
import qualified Amazonka.Lens as Lens
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
(EmailRecipients -> EmailRecipients -> Bool)
-> (EmailRecipients -> EmailRecipients -> Bool)
-> Eq EmailRecipients
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]
(Int -> ReadS EmailRecipients)
-> ReadS [EmailRecipients]
-> ReadPrec EmailRecipients
-> ReadPrec [EmailRecipients]
-> Read 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
(Int -> EmailRecipients -> ShowS)
-> (EmailRecipients -> String)
-> ([EmailRecipients] -> ShowS)
-> Show EmailRecipients
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. EmailRecipients -> Rep EmailRecipients x)
-> (forall x. Rep EmailRecipients x -> EmailRecipients)
-> Generic EmailRecipients
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' :: Maybe (NonEmpty RecipientDetail) -> EmailRecipients
EmailRecipients' {$sel:to:EmailRecipients' :: Maybe (NonEmpty RecipientDetail)
to = Maybe (NonEmpty RecipientDetail)
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 :: (Maybe (NonEmpty RecipientDetail)
 -> f (Maybe (NonEmpty RecipientDetail)))
-> EmailRecipients -> f EmailRecipients
emailRecipients_to = (EmailRecipients -> Maybe (NonEmpty RecipientDetail))
-> (EmailRecipients
    -> Maybe (NonEmpty RecipientDetail) -> EmailRecipients)
-> Lens
     EmailRecipients
     EmailRecipients
     (Maybe (NonEmpty RecipientDetail))
     (Maybe (NonEmpty RecipientDetail))
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) ((Maybe (NonEmpty RecipientDetail)
  -> f (Maybe (NonEmpty RecipientDetail)))
 -> EmailRecipients -> f EmailRecipients)
-> ((Maybe (NonEmpty RecipientDetail)
     -> f (Maybe (NonEmpty RecipientDetail)))
    -> Maybe (NonEmpty RecipientDetail)
    -> f (Maybe (NonEmpty RecipientDetail)))
-> (Maybe (NonEmpty RecipientDetail)
    -> f (Maybe (NonEmpty RecipientDetail)))
-> EmailRecipients
-> f EmailRecipients
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty RecipientDetail)
  (NonEmpty RecipientDetail)
  (NonEmpty RecipientDetail)
  (NonEmpty RecipientDetail)
-> Iso
     (Maybe (NonEmpty RecipientDetail))
     (Maybe (NonEmpty RecipientDetail))
     (Maybe (NonEmpty RecipientDetail))
     (Maybe (NonEmpty RecipientDetail))
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
  (NonEmpty RecipientDetail)
  (NonEmpty RecipientDetail)
  (NonEmpty RecipientDetail)
  (NonEmpty RecipientDetail)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable EmailRecipients

instance Prelude.NFData EmailRecipients

instance Core.ToJSON EmailRecipients where
  toJSON :: EmailRecipients -> Value
toJSON EmailRecipients' {Maybe (NonEmpty RecipientDetail)
to :: Maybe (NonEmpty RecipientDetail)
$sel:to:EmailRecipients' :: EmailRecipients -> Maybe (NonEmpty RecipientDetail)
..} =
    [Pair] -> Value
Core.object
      ([Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes [(Text
"to" Text -> NonEmpty RecipientDetail -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (NonEmpty RecipientDetail -> Pair)
-> Maybe (NonEmpty RecipientDetail) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty RecipientDetail)
to])