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

-- | 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
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]
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
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. 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'
      { $sel:description:Topic' :: Maybe Text
description = 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 :: Lens' Topic (Maybe Text)
topic_description = 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 :: Lens' Topic Text
topic_topicName = 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 :: Lens' Topic Text
topic_displayName = 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 :: Lens' Topic SubscriptionStatus
topic_defaultSubscriptionStatus = 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 Data.FromJSON Topic where
  parseJSON :: Value -> Parser Topic
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Topic"
      ( \Object
x ->
          Maybe Text -> Text -> Text -> SubscriptionStatus -> Topic
Topic'
            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
"Description")
            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
"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
"DisplayName")
            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
"DefaultSubscriptionStatus")
      )

instance Prelude.Hashable Topic where
  hashWithSalt :: Int -> Topic -> Int
hashWithSalt Int
_salt 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
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
description
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
topicName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
displayName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` SubscriptionStatus
defaultSubscriptionStatus

instance Prelude.NFData Topic where
  rnf :: Topic -> ()
rnf 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
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
description
      seq :: forall a b. a -> b -> b
`Prelude.seq` 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 Text
displayName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf SubscriptionStatus
defaultSubscriptionStatus

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Description" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
description,
            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
"DisplayName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
displayName),
            forall a. a -> Maybe a
Prelude.Just
              ( Key
"DefaultSubscriptionStatus"
                  forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= SubscriptionStatus
defaultSubscriptionStatus
              )
          ]
      )