{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.SESV2.Types.Contact where

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 Amazonka.SESV2.Types.TopicPreference

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

-- | The contact\'s email address.
contact_emailAddress :: Lens.Lens' Contact (Prelude.Maybe Prelude.Text)
contact_emailAddress :: Lens' Contact (Maybe Text)
contact_emailAddress = 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 :: Lens' Contact (Maybe UTCTime)
contact_lastUpdatedTimestamp = 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) 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 (a :: Format). Iso' (Time a) UTCTime
Data._Time

-- | The default topic preferences applied to the contact.
contact_topicDefaultPreferences :: Lens.Lens' Contact (Prelude.Maybe [TopicPreference])
contact_topicDefaultPreferences :: Lens' Contact (Maybe [TopicPreference])
contact_topicDefaultPreferences = 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) 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 contact\'s preference for being opted-in to or opted-out of a topic.
contact_topicPreferences :: Lens.Lens' Contact (Prelude.Maybe [TopicPreference])
contact_topicPreferences :: Lens' Contact (Maybe [TopicPreference])
contact_topicPreferences = 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) 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

-- | 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 :: Lens' Contact (Maybe Bool)
contact_unsubscribeAll = 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)

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

instance Prelude.Hashable Contact where
  hashWithSalt :: Int -> Contact -> Int
hashWithSalt Int
_salt Contact' {Maybe Bool
Maybe [TopicPreference]
Maybe Text
Maybe POSIX
unsubscribeAll :: Maybe Bool
topicPreferences :: Maybe [TopicPreference]
topicDefaultPreferences :: Maybe [TopicPreference]
lastUpdatedTimestamp :: Maybe POSIX
emailAddress :: Maybe Text
$sel:unsubscribeAll:Contact' :: Contact -> Maybe Bool
$sel:topicPreferences:Contact' :: Contact -> Maybe [TopicPreference]
$sel:topicDefaultPreferences:Contact' :: Contact -> Maybe [TopicPreference]
$sel:lastUpdatedTimestamp:Contact' :: Contact -> Maybe POSIX
$sel:emailAddress:Contact' :: Contact -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
emailAddress
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe POSIX
lastUpdatedTimestamp
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [TopicPreference]
topicDefaultPreferences
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [TopicPreference]
topicPreferences
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
unsubscribeAll

instance Prelude.NFData Contact where
  rnf :: Contact -> ()
rnf Contact' {Maybe Bool
Maybe [TopicPreference]
Maybe Text
Maybe POSIX
unsubscribeAll :: Maybe Bool
topicPreferences :: Maybe [TopicPreference]
topicDefaultPreferences :: Maybe [TopicPreference]
lastUpdatedTimestamp :: Maybe POSIX
emailAddress :: Maybe Text
$sel:unsubscribeAll:Contact' :: Contact -> Maybe Bool
$sel:topicPreferences:Contact' :: Contact -> Maybe [TopicPreference]
$sel:topicDefaultPreferences:Contact' :: Contact -> Maybe [TopicPreference]
$sel:lastUpdatedTimestamp:Contact' :: Contact -> Maybe POSIX
$sel:emailAddress:Contact' :: Contact -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
emailAddress
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe POSIX
lastUpdatedTimestamp
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [TopicPreference]
topicDefaultPreferences
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [TopicPreference]
topicPreferences
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
unsubscribeAll