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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(TopicPreference -> TopicPreference -> Bool)
-> (TopicPreference -> TopicPreference -> Bool)
-> Eq TopicPreference
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]
(Int -> ReadS TopicPreference)
-> ReadS [TopicPreference]
-> ReadPrec TopicPreference
-> ReadPrec [TopicPreference]
-> Read 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
(Int -> TopicPreference -> ShowS)
-> (TopicPreference -> String)
-> ([TopicPreference] -> ShowS)
-> Show TopicPreference
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. TopicPreference -> Rep TopicPreference x)
-> (forall x. Rep TopicPreference x -> TopicPreference)
-> Generic TopicPreference
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' :: Text -> SubscriptionStatus -> TopicPreference
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 :: (Text -> f Text) -> TopicPreference -> f TopicPreference
topicPreference_topicName = (TopicPreference -> Text)
-> (TopicPreference -> Text -> TopicPreference)
-> Lens TopicPreference TopicPreference Text Text
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 :: (SubscriptionStatus -> f SubscriptionStatus)
-> TopicPreference -> f TopicPreference
topicPreference_subscriptionStatus = (TopicPreference -> SubscriptionStatus)
-> (TopicPreference -> SubscriptionStatus -> TopicPreference)
-> Lens
     TopicPreference
     TopicPreference
     SubscriptionStatus
     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 Core.FromJSON TopicPreference where
  parseJSON :: Value -> Parser TopicPreference
parseJSON =
    String
-> (Object -> Parser TopicPreference)
-> Value
-> Parser TopicPreference
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"TopicPreference"
      ( \Object
x ->
          Text -> SubscriptionStatus -> TopicPreference
TopicPreference'
            (Text -> SubscriptionStatus -> TopicPreference)
-> Parser Text -> Parser (SubscriptionStatus -> TopicPreference)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"TopicName")
            Parser (SubscriptionStatus -> TopicPreference)
-> Parser SubscriptionStatus -> Parser TopicPreference
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser SubscriptionStatus
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"SubscriptionStatus")
      )

instance Prelude.Hashable TopicPreference

instance Prelude.NFData TopicPreference

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"TopicName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
topicName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"SubscriptionStatus" Text -> SubscriptionStatus -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= SubscriptionStatus
subscriptionStatus)
          ]
      )