{-# 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.TopicPreference
-- 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.TopicPreference 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.SubscriptionStatus

-- | The contact\'s preference for being opted-in to or opted-out of a topic.
--
-- /See:/ 'newTopicPreference' smart constructor.
data TopicPreference = TopicPreference'
  { -- | The name of the topic.
    TopicPreference -> Text
topicName :: Prelude.Text,
    -- | The contact\'s subscription status to a topic which is either @OPT_IN@
    -- or @OPT_OUT@.
    TopicPreference -> SubscriptionStatus
subscriptionStatus :: SubscriptionStatus
  }
  deriving (TopicPreference -> TopicPreference -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TopicPreference -> TopicPreference -> Bool
$c/= :: TopicPreference -> TopicPreference -> Bool
== :: TopicPreference -> TopicPreference -> Bool
$c== :: TopicPreference -> TopicPreference -> Bool
Prelude.Eq, ReadPrec [TopicPreference]
ReadPrec TopicPreference
Int -> ReadS TopicPreference
ReadS [TopicPreference]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TopicPreference]
$creadListPrec :: ReadPrec [TopicPreference]
readPrec :: ReadPrec TopicPreference
$creadPrec :: ReadPrec TopicPreference
readList :: ReadS [TopicPreference]
$creadList :: ReadS [TopicPreference]
readsPrec :: Int -> ReadS TopicPreference
$creadsPrec :: Int -> ReadS TopicPreference
Prelude.Read, Int -> TopicPreference -> ShowS
[TopicPreference] -> ShowS
TopicPreference -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TopicPreference] -> ShowS
$cshowList :: [TopicPreference] -> ShowS
show :: TopicPreference -> String
$cshow :: TopicPreference -> String
showsPrec :: Int -> TopicPreference -> ShowS
$cshowsPrec :: Int -> TopicPreference -> ShowS
Prelude.Show, forall x. Rep TopicPreference x -> TopicPreference
forall x. TopicPreference -> Rep TopicPreference x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TopicPreference x -> TopicPreference
$cfrom :: forall x. TopicPreference -> Rep TopicPreference x
Prelude.Generic)

-- |
-- Create a value of 'TopicPreference' 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:
--
-- 'topicName', 'topicPreference_topicName' - The name of the topic.
--
-- 'subscriptionStatus', 'topicPreference_subscriptionStatus' - The contact\'s subscription status to a topic which is either @OPT_IN@
-- or @OPT_OUT@.
newTopicPreference ::
  -- | 'topicName'
  Prelude.Text ->
  -- | 'subscriptionStatus'
  SubscriptionStatus ->
  TopicPreference
newTopicPreference :: Text -> SubscriptionStatus -> TopicPreference
newTopicPreference Text
pTopicName_ SubscriptionStatus
pSubscriptionStatus_ =
  TopicPreference'
    { $sel:topicName:TopicPreference' :: Text
topicName = Text
pTopicName_,
      $sel:subscriptionStatus:TopicPreference' :: SubscriptionStatus
subscriptionStatus = SubscriptionStatus
pSubscriptionStatus_
    }

-- | The name of the topic.
topicPreference_topicName :: Lens.Lens' TopicPreference Prelude.Text
topicPreference_topicName :: Lens' TopicPreference Text
topicPreference_topicName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TopicPreference' {Text
topicName :: Text
$sel:topicName:TopicPreference' :: TopicPreference -> Text
topicName} -> Text
topicName) (\s :: TopicPreference
s@TopicPreference' {} Text
a -> TopicPreference
s {$sel:topicName:TopicPreference' :: Text
topicName = Text
a} :: TopicPreference)

-- | The contact\'s subscription status to a topic which is either @OPT_IN@
-- or @OPT_OUT@.
topicPreference_subscriptionStatus :: Lens.Lens' TopicPreference SubscriptionStatus
topicPreference_subscriptionStatus :: Lens' TopicPreference SubscriptionStatus
topicPreference_subscriptionStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TopicPreference' {SubscriptionStatus
subscriptionStatus :: SubscriptionStatus
$sel:subscriptionStatus:TopicPreference' :: TopicPreference -> SubscriptionStatus
subscriptionStatus} -> SubscriptionStatus
subscriptionStatus) (\s :: TopicPreference
s@TopicPreference' {} SubscriptionStatus
a -> TopicPreference
s {$sel:subscriptionStatus:TopicPreference' :: SubscriptionStatus
subscriptionStatus = SubscriptionStatus
a} :: TopicPreference)

instance Data.FromJSON TopicPreference where
  parseJSON :: Value -> Parser TopicPreference
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"TopicPreference"
      ( \Object
x ->
          Text -> SubscriptionStatus -> TopicPreference
TopicPreference'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"TopicName")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"SubscriptionStatus")
      )

instance Prelude.Hashable TopicPreference where
  hashWithSalt :: Int -> TopicPreference -> Int
hashWithSalt Int
_salt TopicPreference' {Text
SubscriptionStatus
subscriptionStatus :: SubscriptionStatus
topicName :: Text
$sel:subscriptionStatus:TopicPreference' :: TopicPreference -> SubscriptionStatus
$sel:topicName:TopicPreference' :: TopicPreference -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
topicName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` SubscriptionStatus
subscriptionStatus

instance Prelude.NFData TopicPreference where
  rnf :: TopicPreference -> ()
rnf TopicPreference' {Text
SubscriptionStatus
subscriptionStatus :: SubscriptionStatus
topicName :: Text
$sel:subscriptionStatus:TopicPreference' :: TopicPreference -> SubscriptionStatus
$sel:topicName:TopicPreference' :: TopicPreference -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
topicName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf SubscriptionStatus
subscriptionStatus

instance Data.ToJSON TopicPreference where
  toJSON :: TopicPreference -> Value
toJSON TopicPreference' {Text
SubscriptionStatus
subscriptionStatus :: SubscriptionStatus
topicName :: Text
$sel:subscriptionStatus:TopicPreference' :: TopicPreference -> SubscriptionStatus
$sel:topicName:TopicPreference' :: TopicPreference -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"TopicName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
topicName),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"SubscriptionStatus" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= SubscriptionStatus
subscriptionStatus)
          ]
      )