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

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

-- | An interest group, theme, or label within a list. Lists can have
-- multiple topics.
--
-- /See:/ 'newTopic' smart constructor.
data Topic = Topic'
  { -- | A description of what the topic is about, which the contact will see.
    Topic -> Maybe Text
description :: Prelude.Maybe Prelude.Text,
    -- | The name of the topic.
    Topic -> Text
topicName :: Prelude.Text,
    -- | The name of the topic the contact will see.
    Topic -> Text
displayName :: Prelude.Text,
    -- | The default subscription status to be applied to a contact if the
    -- contact has not noted their preference for subscribing to a topic.
    Topic -> SubscriptionStatus
defaultSubscriptionStatus :: SubscriptionStatus
  }
  deriving (Topic -> Topic -> Bool
(Topic -> Topic -> Bool) -> (Topic -> Topic -> Bool) -> Eq Topic
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Topic -> Topic -> Bool
$c/= :: Topic -> Topic -> Bool
== :: Topic -> Topic -> Bool
$c== :: Topic -> Topic -> Bool
Prelude.Eq, ReadPrec [Topic]
ReadPrec Topic
Int -> ReadS Topic
ReadS [Topic]
(Int -> ReadS Topic)
-> ReadS [Topic]
-> ReadPrec Topic
-> ReadPrec [Topic]
-> Read Topic
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Topic]
$creadListPrec :: ReadPrec [Topic]
readPrec :: ReadPrec Topic
$creadPrec :: ReadPrec Topic
readList :: ReadS [Topic]
$creadList :: ReadS [Topic]
readsPrec :: Int -> ReadS Topic
$creadsPrec :: Int -> ReadS Topic
Prelude.Read, Int -> Topic -> ShowS
[Topic] -> ShowS
Topic -> String
(Int -> Topic -> ShowS)
-> (Topic -> String) -> ([Topic] -> ShowS) -> Show Topic
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Topic] -> ShowS
$cshowList :: [Topic] -> ShowS
show :: Topic -> String
$cshow :: Topic -> String
showsPrec :: Int -> Topic -> ShowS
$cshowsPrec :: Int -> Topic -> ShowS
Prelude.Show, (forall x. Topic -> Rep Topic x)
-> (forall x. Rep Topic x -> Topic) -> Generic Topic
forall x. Rep Topic x -> Topic
forall x. Topic -> Rep Topic x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Topic x -> Topic
$cfrom :: forall x. Topic -> Rep Topic x
Prelude.Generic)

-- |
-- Create a value of 'Topic' 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:
--
-- 'description', 'topic_description' - A description of what the topic is about, which the contact will see.
--
-- 'topicName', 'topic_topicName' - The name of the topic.
--
-- 'displayName', 'topic_displayName' - The name of the topic the contact will see.
--
-- 'defaultSubscriptionStatus', 'topic_defaultSubscriptionStatus' - The default subscription status to be applied to a contact if the
-- contact has not noted their preference for subscribing to a topic.
newTopic ::
  -- | 'topicName'
  Prelude.Text ->
  -- | 'displayName'
  Prelude.Text ->
  -- | 'defaultSubscriptionStatus'
  SubscriptionStatus ->
  Topic
newTopic :: Text -> Text -> SubscriptionStatus -> Topic
newTopic
  Text
pTopicName_
  Text
pDisplayName_
  SubscriptionStatus
pDefaultSubscriptionStatus_ =
    Topic' :: Maybe Text -> Text -> Text -> SubscriptionStatus -> Topic
Topic'
      { $sel:description:Topic' :: Maybe Text
description = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:topicName:Topic' :: Text
topicName = Text
pTopicName_,
        $sel:displayName:Topic' :: Text
displayName = Text
pDisplayName_,
        $sel:defaultSubscriptionStatus:Topic' :: SubscriptionStatus
defaultSubscriptionStatus =
          SubscriptionStatus
pDefaultSubscriptionStatus_
      }

-- | A description of what the topic is about, which the contact will see.
topic_description :: Lens.Lens' Topic (Prelude.Maybe Prelude.Text)
topic_description :: (Maybe Text -> f (Maybe Text)) -> Topic -> f Topic
topic_description = (Topic -> Maybe Text)
-> (Topic -> Maybe Text -> Topic)
-> Lens Topic Topic (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Topic' {Maybe Text
description :: Maybe Text
$sel:description:Topic' :: Topic -> Maybe Text
description} -> Maybe Text
description) (\s :: Topic
s@Topic' {} Maybe Text
a -> Topic
s {$sel:description:Topic' :: Maybe Text
description = Maybe Text
a} :: Topic)

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

-- | The name of the topic the contact will see.
topic_displayName :: Lens.Lens' Topic Prelude.Text
topic_displayName :: (Text -> f Text) -> Topic -> f Topic
topic_displayName = (Topic -> Text)
-> (Topic -> Text -> Topic) -> Lens Topic Topic Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Topic' {Text
displayName :: Text
$sel:displayName:Topic' :: Topic -> Text
displayName} -> Text
displayName) (\s :: Topic
s@Topic' {} Text
a -> Topic
s {$sel:displayName:Topic' :: Text
displayName = Text
a} :: Topic)

-- | The default subscription status to be applied to a contact if the
-- contact has not noted their preference for subscribing to a topic.
topic_defaultSubscriptionStatus :: Lens.Lens' Topic SubscriptionStatus
topic_defaultSubscriptionStatus :: (SubscriptionStatus -> f SubscriptionStatus) -> Topic -> f Topic
topic_defaultSubscriptionStatus = (Topic -> SubscriptionStatus)
-> (Topic -> SubscriptionStatus -> Topic)
-> Lens Topic Topic SubscriptionStatus SubscriptionStatus
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Topic' {SubscriptionStatus
defaultSubscriptionStatus :: SubscriptionStatus
$sel:defaultSubscriptionStatus:Topic' :: Topic -> SubscriptionStatus
defaultSubscriptionStatus} -> SubscriptionStatus
defaultSubscriptionStatus) (\s :: Topic
s@Topic' {} SubscriptionStatus
a -> Topic
s {$sel:defaultSubscriptionStatus:Topic' :: SubscriptionStatus
defaultSubscriptionStatus = SubscriptionStatus
a} :: Topic)

instance Core.FromJSON Topic where
  parseJSON :: Value -> Parser Topic
parseJSON =
    String -> (Object -> Parser Topic) -> Value -> Parser Topic
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Topic"
      ( \Object
x ->
          Maybe Text -> Text -> Text -> SubscriptionStatus -> Topic
Topic'
            (Maybe Text -> Text -> Text -> SubscriptionStatus -> Topic)
-> Parser (Maybe Text)
-> Parser (Text -> Text -> SubscriptionStatus -> Topic)
forall (f :: * -> *) a b. Functor 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
"Description")
            Parser (Text -> Text -> SubscriptionStatus -> Topic)
-> Parser Text -> Parser (Text -> SubscriptionStatus -> Topic)
forall (f :: * -> *) a b. Applicative f => 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 (Text -> SubscriptionStatus -> Topic)
-> Parser Text -> Parser (SubscriptionStatus -> Topic)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"DisplayName")
            Parser (SubscriptionStatus -> Topic)
-> Parser SubscriptionStatus -> Parser Topic
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
"DefaultSubscriptionStatus")
      )

instance Prelude.Hashable Topic

instance Prelude.NFData Topic

instance Core.ToJSON Topic where
  toJSON :: Topic -> Value
toJSON Topic' {Maybe Text
Text
SubscriptionStatus
defaultSubscriptionStatus :: SubscriptionStatus
displayName :: Text
topicName :: Text
description :: Maybe Text
$sel:defaultSubscriptionStatus:Topic' :: Topic -> SubscriptionStatus
$sel:displayName:Topic' :: Topic -> Text
$sel:topicName:Topic' :: Topic -> Text
$sel:description:Topic' :: Topic -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Description" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
description,
            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
"DisplayName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
displayName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              ( Text
"DefaultSubscriptionStatus"
                  Text -> SubscriptionStatus -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= SubscriptionStatus
defaultSubscriptionStatus
              )
          ]
      )