{-# 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.SESV2.Types.Contact
-- 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.SESV2.Types.Contact where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.SESV2.Types.TopicPreference

-- | A contact is the end-user who is receiving the email.
--
-- /See:/ 'newContact' smart constructor.
data Contact = Contact'
  { -- | A boolean value status noting if the contact is unsubscribed from all
    -- contact list topics.
    Contact -> Maybe Bool
unsubscribeAll :: Prelude.Maybe Prelude.Bool,
    -- | The default topic preferences applied to the contact.
    Contact -> Maybe [TopicPreference]
topicDefaultPreferences :: Prelude.Maybe [TopicPreference],
    -- | The contact\'s email address.
    Contact -> Maybe Text
emailAddress :: Prelude.Maybe Prelude.Text,
    -- | A timestamp noting the last time the contact\'s information was updated.
    Contact -> Maybe POSIX
lastUpdatedTimestamp :: Prelude.Maybe Core.POSIX,
    -- | The contact\'s preference for being opted-in to or opted-out of a topic.
    Contact -> Maybe [TopicPreference]
topicPreferences :: Prelude.Maybe [TopicPreference]
  }
  deriving (Contact -> Contact -> Bool
(Contact -> Contact -> Bool)
-> (Contact -> Contact -> Bool) -> Eq Contact
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Contact -> Contact -> Bool
$c/= :: Contact -> Contact -> Bool
== :: Contact -> Contact -> Bool
$c== :: Contact -> Contact -> Bool
Prelude.Eq, ReadPrec [Contact]
ReadPrec Contact
Int -> ReadS Contact
ReadS [Contact]
(Int -> ReadS Contact)
-> ReadS [Contact]
-> ReadPrec Contact
-> ReadPrec [Contact]
-> Read Contact
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Contact]
$creadListPrec :: ReadPrec [Contact]
readPrec :: ReadPrec Contact
$creadPrec :: ReadPrec Contact
readList :: ReadS [Contact]
$creadList :: ReadS [Contact]
readsPrec :: Int -> ReadS Contact
$creadsPrec :: Int -> ReadS Contact
Prelude.Read, Int -> Contact -> ShowS
[Contact] -> ShowS
Contact -> String
(Int -> Contact -> ShowS)
-> (Contact -> String) -> ([Contact] -> ShowS) -> Show Contact
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Contact] -> ShowS
$cshowList :: [Contact] -> ShowS
show :: Contact -> String
$cshow :: Contact -> String
showsPrec :: Int -> Contact -> ShowS
$cshowsPrec :: Int -> Contact -> ShowS
Prelude.Show, (forall x. Contact -> Rep Contact x)
-> (forall x. Rep Contact x -> Contact) -> Generic Contact
forall x. Rep Contact x -> Contact
forall x. Contact -> Rep Contact x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Contact x -> Contact
$cfrom :: forall x. Contact -> Rep Contact x
Prelude.Generic)

-- |
-- Create a value of 'Contact' 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:
--
-- 'unsubscribeAll', 'contact_unsubscribeAll' - A boolean value status noting if the contact is unsubscribed from all
-- contact list topics.
--
-- 'topicDefaultPreferences', 'contact_topicDefaultPreferences' - The default topic preferences applied to the contact.
--
-- 'emailAddress', 'contact_emailAddress' - The contact\'s email address.
--
-- 'lastUpdatedTimestamp', 'contact_lastUpdatedTimestamp' - A timestamp noting the last time the contact\'s information was updated.
--
-- 'topicPreferences', 'contact_topicPreferences' - The contact\'s preference for being opted-in to or opted-out of a topic.
newContact ::
  Contact
newContact :: Contact
newContact =
  Contact' :: Maybe Bool
-> Maybe [TopicPreference]
-> Maybe Text
-> Maybe POSIX
-> Maybe [TopicPreference]
-> Contact
Contact'
    { $sel:unsubscribeAll:Contact' :: Maybe Bool
unsubscribeAll = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:topicDefaultPreferences:Contact' :: Maybe [TopicPreference]
topicDefaultPreferences = Maybe [TopicPreference]
forall a. Maybe a
Prelude.Nothing,
      $sel:emailAddress:Contact' :: Maybe Text
emailAddress = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:lastUpdatedTimestamp:Contact' :: Maybe POSIX
lastUpdatedTimestamp = Maybe POSIX
forall a. Maybe a
Prelude.Nothing,
      $sel:topicPreferences:Contact' :: Maybe [TopicPreference]
topicPreferences = Maybe [TopicPreference]
forall a. Maybe a
Prelude.Nothing
    }

-- | A boolean value status noting if the contact is unsubscribed from all
-- contact list topics.
contact_unsubscribeAll :: Lens.Lens' Contact (Prelude.Maybe Prelude.Bool)
contact_unsubscribeAll :: (Maybe Bool -> f (Maybe Bool)) -> Contact -> f Contact
contact_unsubscribeAll = (Contact -> Maybe Bool)
-> (Contact -> Maybe Bool -> Contact)
-> Lens Contact Contact (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Contact' {Maybe Bool
unsubscribeAll :: Maybe Bool
$sel:unsubscribeAll:Contact' :: Contact -> Maybe Bool
unsubscribeAll} -> Maybe Bool
unsubscribeAll) (\s :: Contact
s@Contact' {} Maybe Bool
a -> Contact
s {$sel:unsubscribeAll:Contact' :: Maybe Bool
unsubscribeAll = Maybe Bool
a} :: Contact)

-- | The default topic preferences applied to the contact.
contact_topicDefaultPreferences :: Lens.Lens' Contact (Prelude.Maybe [TopicPreference])
contact_topicDefaultPreferences :: (Maybe [TopicPreference] -> f (Maybe [TopicPreference]))
-> Contact -> f Contact
contact_topicDefaultPreferences = (Contact -> Maybe [TopicPreference])
-> (Contact -> Maybe [TopicPreference] -> Contact)
-> Lens
     Contact Contact (Maybe [TopicPreference]) (Maybe [TopicPreference])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Contact' {Maybe [TopicPreference]
topicDefaultPreferences :: Maybe [TopicPreference]
$sel:topicDefaultPreferences:Contact' :: Contact -> Maybe [TopicPreference]
topicDefaultPreferences} -> Maybe [TopicPreference]
topicDefaultPreferences) (\s :: Contact
s@Contact' {} Maybe [TopicPreference]
a -> Contact
s {$sel:topicDefaultPreferences:Contact' :: Maybe [TopicPreference]
topicDefaultPreferences = Maybe [TopicPreference]
a} :: Contact) ((Maybe [TopicPreference] -> f (Maybe [TopicPreference]))
 -> Contact -> f Contact)
-> ((Maybe [TopicPreference] -> f (Maybe [TopicPreference]))
    -> Maybe [TopicPreference] -> f (Maybe [TopicPreference]))
-> (Maybe [TopicPreference] -> f (Maybe [TopicPreference]))
-> Contact
-> f Contact
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [TopicPreference]
  [TopicPreference]
  [TopicPreference]
  [TopicPreference]
-> Iso
     (Maybe [TopicPreference])
     (Maybe [TopicPreference])
     (Maybe [TopicPreference])
     (Maybe [TopicPreference])
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
  [TopicPreference]
  [TopicPreference]
  [TopicPreference]
  [TopicPreference]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The contact\'s email address.
contact_emailAddress :: Lens.Lens' Contact (Prelude.Maybe Prelude.Text)
contact_emailAddress :: (Maybe Text -> f (Maybe Text)) -> Contact -> f Contact
contact_emailAddress = (Contact -> Maybe Text)
-> (Contact -> Maybe Text -> Contact)
-> Lens Contact Contact (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Contact' {Maybe Text
emailAddress :: Maybe Text
$sel:emailAddress:Contact' :: Contact -> Maybe Text
emailAddress} -> Maybe Text
emailAddress) (\s :: Contact
s@Contact' {} Maybe Text
a -> Contact
s {$sel:emailAddress:Contact' :: Maybe Text
emailAddress = Maybe Text
a} :: Contact)

-- | A timestamp noting the last time the contact\'s information was updated.
contact_lastUpdatedTimestamp :: Lens.Lens' Contact (Prelude.Maybe Prelude.UTCTime)
contact_lastUpdatedTimestamp :: (Maybe UTCTime -> f (Maybe UTCTime)) -> Contact -> f Contact
contact_lastUpdatedTimestamp = (Contact -> Maybe POSIX)
-> (Contact -> Maybe POSIX -> Contact)
-> Lens Contact Contact (Maybe POSIX) (Maybe POSIX)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Contact' {Maybe POSIX
lastUpdatedTimestamp :: Maybe POSIX
$sel:lastUpdatedTimestamp:Contact' :: Contact -> Maybe POSIX
lastUpdatedTimestamp} -> Maybe POSIX
lastUpdatedTimestamp) (\s :: Contact
s@Contact' {} Maybe POSIX
a -> Contact
s {$sel:lastUpdatedTimestamp:Contact' :: Maybe POSIX
lastUpdatedTimestamp = Maybe POSIX
a} :: Contact) ((Maybe POSIX -> f (Maybe POSIX)) -> Contact -> f Contact)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> Contact
-> f Contact
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso POSIX POSIX UTCTime UTCTime
-> Iso (Maybe POSIX) (Maybe POSIX) (Maybe UTCTime) (Maybe UTCTime)
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 POSIX POSIX UTCTime UTCTime
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

-- | The contact\'s preference for being opted-in to or opted-out of a topic.
contact_topicPreferences :: Lens.Lens' Contact (Prelude.Maybe [TopicPreference])
contact_topicPreferences :: (Maybe [TopicPreference] -> f (Maybe [TopicPreference]))
-> Contact -> f Contact
contact_topicPreferences = (Contact -> Maybe [TopicPreference])
-> (Contact -> Maybe [TopicPreference] -> Contact)
-> Lens
     Contact Contact (Maybe [TopicPreference]) (Maybe [TopicPreference])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Contact' {Maybe [TopicPreference]
topicPreferences :: Maybe [TopicPreference]
$sel:topicPreferences:Contact' :: Contact -> Maybe [TopicPreference]
topicPreferences} -> Maybe [TopicPreference]
topicPreferences) (\s :: Contact
s@Contact' {} Maybe [TopicPreference]
a -> Contact
s {$sel:topicPreferences:Contact' :: Maybe [TopicPreference]
topicPreferences = Maybe [TopicPreference]
a} :: Contact) ((Maybe [TopicPreference] -> f (Maybe [TopicPreference]))
 -> Contact -> f Contact)
-> ((Maybe [TopicPreference] -> f (Maybe [TopicPreference]))
    -> Maybe [TopicPreference] -> f (Maybe [TopicPreference]))
-> (Maybe [TopicPreference] -> f (Maybe [TopicPreference]))
-> Contact
-> f Contact
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [TopicPreference]
  [TopicPreference]
  [TopicPreference]
  [TopicPreference]
-> Iso
     (Maybe [TopicPreference])
     (Maybe [TopicPreference])
     (Maybe [TopicPreference])
     (Maybe [TopicPreference])
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
  [TopicPreference]
  [TopicPreference]
  [TopicPreference]
  [TopicPreference]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON Contact where
  parseJSON :: Value -> Parser Contact
parseJSON =
    String -> (Object -> Parser Contact) -> Value -> Parser Contact
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Contact"
      ( \Object
x ->
          Maybe Bool
-> Maybe [TopicPreference]
-> Maybe Text
-> Maybe POSIX
-> Maybe [TopicPreference]
-> Contact
Contact'
            (Maybe Bool
 -> Maybe [TopicPreference]
 -> Maybe Text
 -> Maybe POSIX
 -> Maybe [TopicPreference]
 -> Contact)
-> Parser (Maybe Bool)
-> Parser
     (Maybe [TopicPreference]
      -> Maybe Text -> Maybe POSIX -> Maybe [TopicPreference] -> Contact)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"UnsubscribeAll")
            Parser
  (Maybe [TopicPreference]
   -> Maybe Text -> Maybe POSIX -> Maybe [TopicPreference] -> Contact)
-> Parser (Maybe [TopicPreference])
-> Parser
     (Maybe Text -> Maybe POSIX -> Maybe [TopicPreference] -> Contact)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x Object -> Text -> Parser (Maybe (Maybe [TopicPreference]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"TopicDefaultPreferences"
                            Parser (Maybe (Maybe [TopicPreference]))
-> Maybe [TopicPreference] -> Parser (Maybe [TopicPreference])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [TopicPreference]
forall a. Monoid a => a
Prelude.mempty
                        )
            Parser
  (Maybe Text -> Maybe POSIX -> Maybe [TopicPreference] -> Contact)
-> Parser (Maybe Text)
-> Parser (Maybe POSIX -> Maybe [TopicPreference] -> Contact)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"EmailAddress")
            Parser (Maybe POSIX -> Maybe [TopicPreference] -> Contact)
-> Parser (Maybe POSIX)
-> Parser (Maybe [TopicPreference] -> Contact)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe POSIX)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"LastUpdatedTimestamp")
            Parser (Maybe [TopicPreference] -> Contact)
-> Parser (Maybe [TopicPreference]) -> Parser Contact
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x Object -> Text -> Parser (Maybe (Maybe [TopicPreference]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"TopicPreferences"
                            Parser (Maybe (Maybe [TopicPreference]))
-> Maybe [TopicPreference] -> Parser (Maybe [TopicPreference])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [TopicPreference]
forall a. Monoid a => a
Prelude.mempty
                        )
      )

instance Prelude.Hashable Contact

instance Prelude.NFData Contact