{-# 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.Pinpoint.Types.PushMessageActivity
-- 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.Pinpoint.Types.PushMessageActivity where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.Pinpoint.Types.JourneyPushMessage
import qualified Amazonka.Prelude as Prelude

-- | Specifies the settings for a push notification activity in a journey.
-- This type of activity sends a push notification to participants.
--
-- /See:/ 'newPushMessageActivity' smart constructor.
data PushMessageActivity = PushMessageActivity'
  { -- | The name of the push notification template to use for the message. If
    -- specified, this value must match the name of an existing message
    -- template.
    PushMessageActivity -> Maybe Text
templateName :: Prelude.Maybe Prelude.Text,
    -- | The unique identifier for the version of the push notification template
    -- to use for the message. If specified, this value must match the
    -- identifier for an existing template version. To retrieve a list of
    -- versions and version identifiers for a template, use the Template
    -- Versions resource.
    --
    -- If you don\'t specify a value for this property, Amazon Pinpoint uses
    -- the /active version/ of the template. The /active version/ is typically
    -- the version of a template that\'s been most recently reviewed and
    -- approved for use, depending on your workflow. It isn\'t necessarily the
    -- latest version of a template.
    PushMessageActivity -> Maybe Text
templateVersion :: Prelude.Maybe Prelude.Text,
    -- | The unique identifier for the next activity to perform, after the
    -- message is sent.
    PushMessageActivity -> Maybe Text
nextActivity :: Prelude.Maybe Prelude.Text,
    -- | Specifies the time to live (TTL) value for push notifications that are
    -- sent to participants in a journey.
    PushMessageActivity -> Maybe JourneyPushMessage
messageConfig :: Prelude.Maybe JourneyPushMessage
  }
  deriving (PushMessageActivity -> PushMessageActivity -> Bool
(PushMessageActivity -> PushMessageActivity -> Bool)
-> (PushMessageActivity -> PushMessageActivity -> Bool)
-> Eq PushMessageActivity
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PushMessageActivity -> PushMessageActivity -> Bool
$c/= :: PushMessageActivity -> PushMessageActivity -> Bool
== :: PushMessageActivity -> PushMessageActivity -> Bool
$c== :: PushMessageActivity -> PushMessageActivity -> Bool
Prelude.Eq, ReadPrec [PushMessageActivity]
ReadPrec PushMessageActivity
Int -> ReadS PushMessageActivity
ReadS [PushMessageActivity]
(Int -> ReadS PushMessageActivity)
-> ReadS [PushMessageActivity]
-> ReadPrec PushMessageActivity
-> ReadPrec [PushMessageActivity]
-> Read PushMessageActivity
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PushMessageActivity]
$creadListPrec :: ReadPrec [PushMessageActivity]
readPrec :: ReadPrec PushMessageActivity
$creadPrec :: ReadPrec PushMessageActivity
readList :: ReadS [PushMessageActivity]
$creadList :: ReadS [PushMessageActivity]
readsPrec :: Int -> ReadS PushMessageActivity
$creadsPrec :: Int -> ReadS PushMessageActivity
Prelude.Read, Int -> PushMessageActivity -> ShowS
[PushMessageActivity] -> ShowS
PushMessageActivity -> String
(Int -> PushMessageActivity -> ShowS)
-> (PushMessageActivity -> String)
-> ([PushMessageActivity] -> ShowS)
-> Show PushMessageActivity
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PushMessageActivity] -> ShowS
$cshowList :: [PushMessageActivity] -> ShowS
show :: PushMessageActivity -> String
$cshow :: PushMessageActivity -> String
showsPrec :: Int -> PushMessageActivity -> ShowS
$cshowsPrec :: Int -> PushMessageActivity -> ShowS
Prelude.Show, (forall x. PushMessageActivity -> Rep PushMessageActivity x)
-> (forall x. Rep PushMessageActivity x -> PushMessageActivity)
-> Generic PushMessageActivity
forall x. Rep PushMessageActivity x -> PushMessageActivity
forall x. PushMessageActivity -> Rep PushMessageActivity x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PushMessageActivity x -> PushMessageActivity
$cfrom :: forall x. PushMessageActivity -> Rep PushMessageActivity x
Prelude.Generic)

-- |
-- Create a value of 'PushMessageActivity' 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:
--
-- 'templateName', 'pushMessageActivity_templateName' - The name of the push notification template to use for the message. If
-- specified, this value must match the name of an existing message
-- template.
--
-- 'templateVersion', 'pushMessageActivity_templateVersion' - The unique identifier for the version of the push notification template
-- to use for the message. If specified, this value must match the
-- identifier for an existing template version. To retrieve a list of
-- versions and version identifiers for a template, use the Template
-- Versions resource.
--
-- If you don\'t specify a value for this property, Amazon Pinpoint uses
-- the /active version/ of the template. The /active version/ is typically
-- the version of a template that\'s been most recently reviewed and
-- approved for use, depending on your workflow. It isn\'t necessarily the
-- latest version of a template.
--
-- 'nextActivity', 'pushMessageActivity_nextActivity' - The unique identifier for the next activity to perform, after the
-- message is sent.
--
-- 'messageConfig', 'pushMessageActivity_messageConfig' - Specifies the time to live (TTL) value for push notifications that are
-- sent to participants in a journey.
newPushMessageActivity ::
  PushMessageActivity
newPushMessageActivity :: PushMessageActivity
newPushMessageActivity =
  PushMessageActivity' :: Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe JourneyPushMessage
-> PushMessageActivity
PushMessageActivity'
    { $sel:templateName:PushMessageActivity' :: Maybe Text
templateName =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:templateVersion:PushMessageActivity' :: Maybe Text
templateVersion = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:nextActivity:PushMessageActivity' :: Maybe Text
nextActivity = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:messageConfig:PushMessageActivity' :: Maybe JourneyPushMessage
messageConfig = Maybe JourneyPushMessage
forall a. Maybe a
Prelude.Nothing
    }

-- | The name of the push notification template to use for the message. If
-- specified, this value must match the name of an existing message
-- template.
pushMessageActivity_templateName :: Lens.Lens' PushMessageActivity (Prelude.Maybe Prelude.Text)
pushMessageActivity_templateName :: (Maybe Text -> f (Maybe Text))
-> PushMessageActivity -> f PushMessageActivity
pushMessageActivity_templateName = (PushMessageActivity -> Maybe Text)
-> (PushMessageActivity -> Maybe Text -> PushMessageActivity)
-> Lens
     PushMessageActivity PushMessageActivity (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PushMessageActivity' {Maybe Text
templateName :: Maybe Text
$sel:templateName:PushMessageActivity' :: PushMessageActivity -> Maybe Text
templateName} -> Maybe Text
templateName) (\s :: PushMessageActivity
s@PushMessageActivity' {} Maybe Text
a -> PushMessageActivity
s {$sel:templateName:PushMessageActivity' :: Maybe Text
templateName = Maybe Text
a} :: PushMessageActivity)

-- | The unique identifier for the version of the push notification template
-- to use for the message. If specified, this value must match the
-- identifier for an existing template version. To retrieve a list of
-- versions and version identifiers for a template, use the Template
-- Versions resource.
--
-- If you don\'t specify a value for this property, Amazon Pinpoint uses
-- the /active version/ of the template. The /active version/ is typically
-- the version of a template that\'s been most recently reviewed and
-- approved for use, depending on your workflow. It isn\'t necessarily the
-- latest version of a template.
pushMessageActivity_templateVersion :: Lens.Lens' PushMessageActivity (Prelude.Maybe Prelude.Text)
pushMessageActivity_templateVersion :: (Maybe Text -> f (Maybe Text))
-> PushMessageActivity -> f PushMessageActivity
pushMessageActivity_templateVersion = (PushMessageActivity -> Maybe Text)
-> (PushMessageActivity -> Maybe Text -> PushMessageActivity)
-> Lens
     PushMessageActivity PushMessageActivity (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PushMessageActivity' {Maybe Text
templateVersion :: Maybe Text
$sel:templateVersion:PushMessageActivity' :: PushMessageActivity -> Maybe Text
templateVersion} -> Maybe Text
templateVersion) (\s :: PushMessageActivity
s@PushMessageActivity' {} Maybe Text
a -> PushMessageActivity
s {$sel:templateVersion:PushMessageActivity' :: Maybe Text
templateVersion = Maybe Text
a} :: PushMessageActivity)

-- | The unique identifier for the next activity to perform, after the
-- message is sent.
pushMessageActivity_nextActivity :: Lens.Lens' PushMessageActivity (Prelude.Maybe Prelude.Text)
pushMessageActivity_nextActivity :: (Maybe Text -> f (Maybe Text))
-> PushMessageActivity -> f PushMessageActivity
pushMessageActivity_nextActivity = (PushMessageActivity -> Maybe Text)
-> (PushMessageActivity -> Maybe Text -> PushMessageActivity)
-> Lens
     PushMessageActivity PushMessageActivity (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PushMessageActivity' {Maybe Text
nextActivity :: Maybe Text
$sel:nextActivity:PushMessageActivity' :: PushMessageActivity -> Maybe Text
nextActivity} -> Maybe Text
nextActivity) (\s :: PushMessageActivity
s@PushMessageActivity' {} Maybe Text
a -> PushMessageActivity
s {$sel:nextActivity:PushMessageActivity' :: Maybe Text
nextActivity = Maybe Text
a} :: PushMessageActivity)

-- | Specifies the time to live (TTL) value for push notifications that are
-- sent to participants in a journey.
pushMessageActivity_messageConfig :: Lens.Lens' PushMessageActivity (Prelude.Maybe JourneyPushMessage)
pushMessageActivity_messageConfig :: (Maybe JourneyPushMessage -> f (Maybe JourneyPushMessage))
-> PushMessageActivity -> f PushMessageActivity
pushMessageActivity_messageConfig = (PushMessageActivity -> Maybe JourneyPushMessage)
-> (PushMessageActivity
    -> Maybe JourneyPushMessage -> PushMessageActivity)
-> Lens
     PushMessageActivity
     PushMessageActivity
     (Maybe JourneyPushMessage)
     (Maybe JourneyPushMessage)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PushMessageActivity' {Maybe JourneyPushMessage
messageConfig :: Maybe JourneyPushMessage
$sel:messageConfig:PushMessageActivity' :: PushMessageActivity -> Maybe JourneyPushMessage
messageConfig} -> Maybe JourneyPushMessage
messageConfig) (\s :: PushMessageActivity
s@PushMessageActivity' {} Maybe JourneyPushMessage
a -> PushMessageActivity
s {$sel:messageConfig:PushMessageActivity' :: Maybe JourneyPushMessage
messageConfig = Maybe JourneyPushMessage
a} :: PushMessageActivity)

instance Core.FromJSON PushMessageActivity where
  parseJSON :: Value -> Parser PushMessageActivity
parseJSON =
    String
-> (Object -> Parser PushMessageActivity)
-> Value
-> Parser PushMessageActivity
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"PushMessageActivity"
      ( \Object
x ->
          Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe JourneyPushMessage
-> PushMessageActivity
PushMessageActivity'
            (Maybe Text
 -> Maybe Text
 -> Maybe Text
 -> Maybe JourneyPushMessage
 -> PushMessageActivity)
-> Parser (Maybe Text)
-> Parser
     (Maybe Text
      -> Maybe Text -> Maybe JourneyPushMessage -> PushMessageActivity)
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
"TemplateName")
            Parser
  (Maybe Text
   -> Maybe Text -> Maybe JourneyPushMessage -> PushMessageActivity)
-> Parser (Maybe Text)
-> Parser
     (Maybe Text -> Maybe JourneyPushMessage -> PushMessageActivity)
forall (f :: * -> *) a b. Applicative f => 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
"TemplateVersion")
            Parser
  (Maybe Text -> Maybe JourneyPushMessage -> PushMessageActivity)
-> Parser (Maybe Text)
-> Parser (Maybe JourneyPushMessage -> PushMessageActivity)
forall (f :: * -> *) a b. Applicative f => 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
"NextActivity")
            Parser (Maybe JourneyPushMessage -> PushMessageActivity)
-> Parser (Maybe JourneyPushMessage) -> Parser PushMessageActivity
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe JourneyPushMessage)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"MessageConfig")
      )

instance Prelude.Hashable PushMessageActivity

instance Prelude.NFData PushMessageActivity

instance Core.ToJSON PushMessageActivity where
  toJSON :: PushMessageActivity -> Value
toJSON PushMessageActivity' {Maybe Text
Maybe JourneyPushMessage
messageConfig :: Maybe JourneyPushMessage
nextActivity :: Maybe Text
templateVersion :: Maybe Text
templateName :: Maybe Text
$sel:messageConfig:PushMessageActivity' :: PushMessageActivity -> Maybe JourneyPushMessage
$sel:nextActivity:PushMessageActivity' :: PushMessageActivity -> Maybe Text
$sel:templateVersion:PushMessageActivity' :: PushMessageActivity -> Maybe Text
$sel:templateName:PushMessageActivity' :: PushMessageActivity -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"TemplateName" 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
templateName,
            (Text
"TemplateVersion" 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
templateVersion,
            (Text
"NextActivity" 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
nextActivity,
            (Text
"MessageConfig" Text -> JourneyPushMessage -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (JourneyPushMessage -> Pair)
-> Maybe JourneyPushMessage -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe JourneyPushMessage
messageConfig
          ]
      )