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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.Pinpoint.Types.Condition
import Amazonka.Pinpoint.Types.WaitTime
import qualified Amazonka.Prelude as Prelude

-- | Specifies the settings for a yes\/no split activity in a journey. This
-- type of activity sends participants down one of two paths in a journey,
-- based on conditions that you specify.
--
-- To create yes\/no split activities that send participants down different
-- paths based on push notification events (such as Open or Received
-- events), your mobile app has to specify the User ID and Endpoint ID
-- values. For more information, see
-- <https://docs.aws.amazon.com/pinpoint/latest/developerguide/integrate.html Integrating Amazon Pinpoint with your application>
-- in the /Amazon Pinpoint Developer Guide/.
--
-- /See:/ 'newConditionalSplitActivity' smart constructor.
data ConditionalSplitActivity = ConditionalSplitActivity'
  { -- | The amount of time to wait before determining whether the conditions are
    -- met, or the date and time when Amazon Pinpoint determines whether the
    -- conditions are met.
    ConditionalSplitActivity -> Maybe WaitTime
evaluationWaitTime :: Prelude.Maybe WaitTime,
    -- | The unique identifier for the activity to perform if the conditions are
    -- met.
    ConditionalSplitActivity -> Maybe Text
trueActivity :: Prelude.Maybe Prelude.Text,
    -- | The unique identifier for the activity to perform if the conditions
    -- aren\'t met.
    ConditionalSplitActivity -> Maybe Text
falseActivity :: Prelude.Maybe Prelude.Text,
    -- | The conditions that define the paths for the activity, and the
    -- relationship between the conditions.
    ConditionalSplitActivity -> Maybe Condition
condition :: Prelude.Maybe Condition
  }
  deriving (ConditionalSplitActivity -> ConditionalSplitActivity -> Bool
(ConditionalSplitActivity -> ConditionalSplitActivity -> Bool)
-> (ConditionalSplitActivity -> ConditionalSplitActivity -> Bool)
-> Eq ConditionalSplitActivity
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ConditionalSplitActivity -> ConditionalSplitActivity -> Bool
$c/= :: ConditionalSplitActivity -> ConditionalSplitActivity -> Bool
== :: ConditionalSplitActivity -> ConditionalSplitActivity -> Bool
$c== :: ConditionalSplitActivity -> ConditionalSplitActivity -> Bool
Prelude.Eq, ReadPrec [ConditionalSplitActivity]
ReadPrec ConditionalSplitActivity
Int -> ReadS ConditionalSplitActivity
ReadS [ConditionalSplitActivity]
(Int -> ReadS ConditionalSplitActivity)
-> ReadS [ConditionalSplitActivity]
-> ReadPrec ConditionalSplitActivity
-> ReadPrec [ConditionalSplitActivity]
-> Read ConditionalSplitActivity
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ConditionalSplitActivity]
$creadListPrec :: ReadPrec [ConditionalSplitActivity]
readPrec :: ReadPrec ConditionalSplitActivity
$creadPrec :: ReadPrec ConditionalSplitActivity
readList :: ReadS [ConditionalSplitActivity]
$creadList :: ReadS [ConditionalSplitActivity]
readsPrec :: Int -> ReadS ConditionalSplitActivity
$creadsPrec :: Int -> ReadS ConditionalSplitActivity
Prelude.Read, Int -> ConditionalSplitActivity -> ShowS
[ConditionalSplitActivity] -> ShowS
ConditionalSplitActivity -> String
(Int -> ConditionalSplitActivity -> ShowS)
-> (ConditionalSplitActivity -> String)
-> ([ConditionalSplitActivity] -> ShowS)
-> Show ConditionalSplitActivity
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ConditionalSplitActivity] -> ShowS
$cshowList :: [ConditionalSplitActivity] -> ShowS
show :: ConditionalSplitActivity -> String
$cshow :: ConditionalSplitActivity -> String
showsPrec :: Int -> ConditionalSplitActivity -> ShowS
$cshowsPrec :: Int -> ConditionalSplitActivity -> ShowS
Prelude.Show, (forall x.
 ConditionalSplitActivity -> Rep ConditionalSplitActivity x)
-> (forall x.
    Rep ConditionalSplitActivity x -> ConditionalSplitActivity)
-> Generic ConditionalSplitActivity
forall x.
Rep ConditionalSplitActivity x -> ConditionalSplitActivity
forall x.
ConditionalSplitActivity -> Rep ConditionalSplitActivity x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ConditionalSplitActivity x -> ConditionalSplitActivity
$cfrom :: forall x.
ConditionalSplitActivity -> Rep ConditionalSplitActivity x
Prelude.Generic)

-- |
-- Create a value of 'ConditionalSplitActivity' 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:
--
-- 'evaluationWaitTime', 'conditionalSplitActivity_evaluationWaitTime' - The amount of time to wait before determining whether the conditions are
-- met, or the date and time when Amazon Pinpoint determines whether the
-- conditions are met.
--
-- 'trueActivity', 'conditionalSplitActivity_trueActivity' - The unique identifier for the activity to perform if the conditions are
-- met.
--
-- 'falseActivity', 'conditionalSplitActivity_falseActivity' - The unique identifier for the activity to perform if the conditions
-- aren\'t met.
--
-- 'condition', 'conditionalSplitActivity_condition' - The conditions that define the paths for the activity, and the
-- relationship between the conditions.
newConditionalSplitActivity ::
  ConditionalSplitActivity
newConditionalSplitActivity :: ConditionalSplitActivity
newConditionalSplitActivity =
  ConditionalSplitActivity' :: Maybe WaitTime
-> Maybe Text
-> Maybe Text
-> Maybe Condition
-> ConditionalSplitActivity
ConditionalSplitActivity'
    { $sel:evaluationWaitTime:ConditionalSplitActivity' :: Maybe WaitTime
evaluationWaitTime =
        Maybe WaitTime
forall a. Maybe a
Prelude.Nothing,
      $sel:trueActivity:ConditionalSplitActivity' :: Maybe Text
trueActivity = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:falseActivity:ConditionalSplitActivity' :: Maybe Text
falseActivity = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:condition:ConditionalSplitActivity' :: Maybe Condition
condition = Maybe Condition
forall a. Maybe a
Prelude.Nothing
    }

-- | The amount of time to wait before determining whether the conditions are
-- met, or the date and time when Amazon Pinpoint determines whether the
-- conditions are met.
conditionalSplitActivity_evaluationWaitTime :: Lens.Lens' ConditionalSplitActivity (Prelude.Maybe WaitTime)
conditionalSplitActivity_evaluationWaitTime :: (Maybe WaitTime -> f (Maybe WaitTime))
-> ConditionalSplitActivity -> f ConditionalSplitActivity
conditionalSplitActivity_evaluationWaitTime = (ConditionalSplitActivity -> Maybe WaitTime)
-> (ConditionalSplitActivity
    -> Maybe WaitTime -> ConditionalSplitActivity)
-> Lens
     ConditionalSplitActivity
     ConditionalSplitActivity
     (Maybe WaitTime)
     (Maybe WaitTime)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ConditionalSplitActivity' {Maybe WaitTime
evaluationWaitTime :: Maybe WaitTime
$sel:evaluationWaitTime:ConditionalSplitActivity' :: ConditionalSplitActivity -> Maybe WaitTime
evaluationWaitTime} -> Maybe WaitTime
evaluationWaitTime) (\s :: ConditionalSplitActivity
s@ConditionalSplitActivity' {} Maybe WaitTime
a -> ConditionalSplitActivity
s {$sel:evaluationWaitTime:ConditionalSplitActivity' :: Maybe WaitTime
evaluationWaitTime = Maybe WaitTime
a} :: ConditionalSplitActivity)

-- | The unique identifier for the activity to perform if the conditions are
-- met.
conditionalSplitActivity_trueActivity :: Lens.Lens' ConditionalSplitActivity (Prelude.Maybe Prelude.Text)
conditionalSplitActivity_trueActivity :: (Maybe Text -> f (Maybe Text))
-> ConditionalSplitActivity -> f ConditionalSplitActivity
conditionalSplitActivity_trueActivity = (ConditionalSplitActivity -> Maybe Text)
-> (ConditionalSplitActivity
    -> Maybe Text -> ConditionalSplitActivity)
-> Lens
     ConditionalSplitActivity
     ConditionalSplitActivity
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ConditionalSplitActivity' {Maybe Text
trueActivity :: Maybe Text
$sel:trueActivity:ConditionalSplitActivity' :: ConditionalSplitActivity -> Maybe Text
trueActivity} -> Maybe Text
trueActivity) (\s :: ConditionalSplitActivity
s@ConditionalSplitActivity' {} Maybe Text
a -> ConditionalSplitActivity
s {$sel:trueActivity:ConditionalSplitActivity' :: Maybe Text
trueActivity = Maybe Text
a} :: ConditionalSplitActivity)

-- | The unique identifier for the activity to perform if the conditions
-- aren\'t met.
conditionalSplitActivity_falseActivity :: Lens.Lens' ConditionalSplitActivity (Prelude.Maybe Prelude.Text)
conditionalSplitActivity_falseActivity :: (Maybe Text -> f (Maybe Text))
-> ConditionalSplitActivity -> f ConditionalSplitActivity
conditionalSplitActivity_falseActivity = (ConditionalSplitActivity -> Maybe Text)
-> (ConditionalSplitActivity
    -> Maybe Text -> ConditionalSplitActivity)
-> Lens
     ConditionalSplitActivity
     ConditionalSplitActivity
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ConditionalSplitActivity' {Maybe Text
falseActivity :: Maybe Text
$sel:falseActivity:ConditionalSplitActivity' :: ConditionalSplitActivity -> Maybe Text
falseActivity} -> Maybe Text
falseActivity) (\s :: ConditionalSplitActivity
s@ConditionalSplitActivity' {} Maybe Text
a -> ConditionalSplitActivity
s {$sel:falseActivity:ConditionalSplitActivity' :: Maybe Text
falseActivity = Maybe Text
a} :: ConditionalSplitActivity)

-- | The conditions that define the paths for the activity, and the
-- relationship between the conditions.
conditionalSplitActivity_condition :: Lens.Lens' ConditionalSplitActivity (Prelude.Maybe Condition)
conditionalSplitActivity_condition :: (Maybe Condition -> f (Maybe Condition))
-> ConditionalSplitActivity -> f ConditionalSplitActivity
conditionalSplitActivity_condition = (ConditionalSplitActivity -> Maybe Condition)
-> (ConditionalSplitActivity
    -> Maybe Condition -> ConditionalSplitActivity)
-> Lens
     ConditionalSplitActivity
     ConditionalSplitActivity
     (Maybe Condition)
     (Maybe Condition)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ConditionalSplitActivity' {Maybe Condition
condition :: Maybe Condition
$sel:condition:ConditionalSplitActivity' :: ConditionalSplitActivity -> Maybe Condition
condition} -> Maybe Condition
condition) (\s :: ConditionalSplitActivity
s@ConditionalSplitActivity' {} Maybe Condition
a -> ConditionalSplitActivity
s {$sel:condition:ConditionalSplitActivity' :: Maybe Condition
condition = Maybe Condition
a} :: ConditionalSplitActivity)

instance Core.FromJSON ConditionalSplitActivity where
  parseJSON :: Value -> Parser ConditionalSplitActivity
parseJSON =
    String
-> (Object -> Parser ConditionalSplitActivity)
-> Value
-> Parser ConditionalSplitActivity
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ConditionalSplitActivity"
      ( \Object
x ->
          Maybe WaitTime
-> Maybe Text
-> Maybe Text
-> Maybe Condition
-> ConditionalSplitActivity
ConditionalSplitActivity'
            (Maybe WaitTime
 -> Maybe Text
 -> Maybe Text
 -> Maybe Condition
 -> ConditionalSplitActivity)
-> Parser (Maybe WaitTime)
-> Parser
     (Maybe Text
      -> Maybe Text -> Maybe Condition -> ConditionalSplitActivity)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe WaitTime)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"EvaluationWaitTime")
            Parser
  (Maybe Text
   -> Maybe Text -> Maybe Condition -> ConditionalSplitActivity)
-> Parser (Maybe Text)
-> Parser
     (Maybe Text -> Maybe Condition -> ConditionalSplitActivity)
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
"TrueActivity")
            Parser (Maybe Text -> Maybe Condition -> ConditionalSplitActivity)
-> Parser (Maybe Text)
-> Parser (Maybe Condition -> ConditionalSplitActivity)
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
"FalseActivity")
            Parser (Maybe Condition -> ConditionalSplitActivity)
-> Parser (Maybe Condition) -> Parser ConditionalSplitActivity
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Condition)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Condition")
      )

instance Prelude.Hashable ConditionalSplitActivity

instance Prelude.NFData ConditionalSplitActivity

instance Core.ToJSON ConditionalSplitActivity where
  toJSON :: ConditionalSplitActivity -> Value
toJSON ConditionalSplitActivity' {Maybe Text
Maybe Condition
Maybe WaitTime
condition :: Maybe Condition
falseActivity :: Maybe Text
trueActivity :: Maybe Text
evaluationWaitTime :: Maybe WaitTime
$sel:condition:ConditionalSplitActivity' :: ConditionalSplitActivity -> Maybe Condition
$sel:falseActivity:ConditionalSplitActivity' :: ConditionalSplitActivity -> Maybe Text
$sel:trueActivity:ConditionalSplitActivity' :: ConditionalSplitActivity -> Maybe Text
$sel:evaluationWaitTime:ConditionalSplitActivity' :: ConditionalSplitActivity -> Maybe WaitTime
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"EvaluationWaitTime" Text -> WaitTime -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (WaitTime -> Pair) -> Maybe WaitTime -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe WaitTime
evaluationWaitTime,
            (Text
"TrueActivity" 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
trueActivity,
            (Text
"FalseActivity" 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
falseActivity,
            (Text
"Condition" Text -> Condition -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Condition -> Pair) -> Maybe Condition -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Condition
condition
          ]
      )