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

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

-- | Specifies the settings for a multivariate split activity in a journey.
-- This type of activity sends participants down one of as many as five
-- paths (including a default /Else/ path) in a journey, based on
-- conditions that you specify.
--
-- To create multivariate 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:/ 'newMultiConditionalSplitActivity' smart constructor.
data MultiConditionalSplitActivity = MultiConditionalSplitActivity'
  { -- | The paths for the activity, including the conditions for entering each
    -- path and the activity to perform for each path.
    MultiConditionalSplitActivity -> Maybe [MultiConditionalBranch]
branches :: Prelude.Maybe [MultiConditionalBranch],
    -- | The amount of time to wait or the date and time when Amazon Pinpoint
    -- determines whether the conditions are met.
    MultiConditionalSplitActivity -> Maybe WaitTime
evaluationWaitTime :: Prelude.Maybe WaitTime,
    -- | The unique identifier for the activity to perform for participants who
    -- don\'t meet any of the conditions specified for other paths in the
    -- activity.
    MultiConditionalSplitActivity -> Maybe Text
defaultActivity :: Prelude.Maybe Prelude.Text
  }
  deriving (MultiConditionalSplitActivity
-> MultiConditionalSplitActivity -> Bool
(MultiConditionalSplitActivity
 -> MultiConditionalSplitActivity -> Bool)
-> (MultiConditionalSplitActivity
    -> MultiConditionalSplitActivity -> Bool)
-> Eq MultiConditionalSplitActivity
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MultiConditionalSplitActivity
-> MultiConditionalSplitActivity -> Bool
$c/= :: MultiConditionalSplitActivity
-> MultiConditionalSplitActivity -> Bool
== :: MultiConditionalSplitActivity
-> MultiConditionalSplitActivity -> Bool
$c== :: MultiConditionalSplitActivity
-> MultiConditionalSplitActivity -> Bool
Prelude.Eq, ReadPrec [MultiConditionalSplitActivity]
ReadPrec MultiConditionalSplitActivity
Int -> ReadS MultiConditionalSplitActivity
ReadS [MultiConditionalSplitActivity]
(Int -> ReadS MultiConditionalSplitActivity)
-> ReadS [MultiConditionalSplitActivity]
-> ReadPrec MultiConditionalSplitActivity
-> ReadPrec [MultiConditionalSplitActivity]
-> Read MultiConditionalSplitActivity
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MultiConditionalSplitActivity]
$creadListPrec :: ReadPrec [MultiConditionalSplitActivity]
readPrec :: ReadPrec MultiConditionalSplitActivity
$creadPrec :: ReadPrec MultiConditionalSplitActivity
readList :: ReadS [MultiConditionalSplitActivity]
$creadList :: ReadS [MultiConditionalSplitActivity]
readsPrec :: Int -> ReadS MultiConditionalSplitActivity
$creadsPrec :: Int -> ReadS MultiConditionalSplitActivity
Prelude.Read, Int -> MultiConditionalSplitActivity -> ShowS
[MultiConditionalSplitActivity] -> ShowS
MultiConditionalSplitActivity -> String
(Int -> MultiConditionalSplitActivity -> ShowS)
-> (MultiConditionalSplitActivity -> String)
-> ([MultiConditionalSplitActivity] -> ShowS)
-> Show MultiConditionalSplitActivity
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MultiConditionalSplitActivity] -> ShowS
$cshowList :: [MultiConditionalSplitActivity] -> ShowS
show :: MultiConditionalSplitActivity -> String
$cshow :: MultiConditionalSplitActivity -> String
showsPrec :: Int -> MultiConditionalSplitActivity -> ShowS
$cshowsPrec :: Int -> MultiConditionalSplitActivity -> ShowS
Prelude.Show, (forall x.
 MultiConditionalSplitActivity
 -> Rep MultiConditionalSplitActivity x)
-> (forall x.
    Rep MultiConditionalSplitActivity x
    -> MultiConditionalSplitActivity)
-> Generic MultiConditionalSplitActivity
forall x.
Rep MultiConditionalSplitActivity x
-> MultiConditionalSplitActivity
forall x.
MultiConditionalSplitActivity
-> Rep MultiConditionalSplitActivity x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep MultiConditionalSplitActivity x
-> MultiConditionalSplitActivity
$cfrom :: forall x.
MultiConditionalSplitActivity
-> Rep MultiConditionalSplitActivity x
Prelude.Generic)

-- |
-- Create a value of 'MultiConditionalSplitActivity' 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:
--
-- 'branches', 'multiConditionalSplitActivity_branches' - The paths for the activity, including the conditions for entering each
-- path and the activity to perform for each path.
--
-- 'evaluationWaitTime', 'multiConditionalSplitActivity_evaluationWaitTime' - The amount of time to wait or the date and time when Amazon Pinpoint
-- determines whether the conditions are met.
--
-- 'defaultActivity', 'multiConditionalSplitActivity_defaultActivity' - The unique identifier for the activity to perform for participants who
-- don\'t meet any of the conditions specified for other paths in the
-- activity.
newMultiConditionalSplitActivity ::
  MultiConditionalSplitActivity
newMultiConditionalSplitActivity :: MultiConditionalSplitActivity
newMultiConditionalSplitActivity =
  MultiConditionalSplitActivity' :: Maybe [MultiConditionalBranch]
-> Maybe WaitTime -> Maybe Text -> MultiConditionalSplitActivity
MultiConditionalSplitActivity'
    { $sel:branches:MultiConditionalSplitActivity' :: Maybe [MultiConditionalBranch]
branches =
        Maybe [MultiConditionalBranch]
forall a. Maybe a
Prelude.Nothing,
      $sel:evaluationWaitTime:MultiConditionalSplitActivity' :: Maybe WaitTime
evaluationWaitTime = Maybe WaitTime
forall a. Maybe a
Prelude.Nothing,
      $sel:defaultActivity:MultiConditionalSplitActivity' :: Maybe Text
defaultActivity = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The paths for the activity, including the conditions for entering each
-- path and the activity to perform for each path.
multiConditionalSplitActivity_branches :: Lens.Lens' MultiConditionalSplitActivity (Prelude.Maybe [MultiConditionalBranch])
multiConditionalSplitActivity_branches :: (Maybe [MultiConditionalBranch]
 -> f (Maybe [MultiConditionalBranch]))
-> MultiConditionalSplitActivity -> f MultiConditionalSplitActivity
multiConditionalSplitActivity_branches = (MultiConditionalSplitActivity -> Maybe [MultiConditionalBranch])
-> (MultiConditionalSplitActivity
    -> Maybe [MultiConditionalBranch] -> MultiConditionalSplitActivity)
-> Lens
     MultiConditionalSplitActivity
     MultiConditionalSplitActivity
     (Maybe [MultiConditionalBranch])
     (Maybe [MultiConditionalBranch])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MultiConditionalSplitActivity' {Maybe [MultiConditionalBranch]
branches :: Maybe [MultiConditionalBranch]
$sel:branches:MultiConditionalSplitActivity' :: MultiConditionalSplitActivity -> Maybe [MultiConditionalBranch]
branches} -> Maybe [MultiConditionalBranch]
branches) (\s :: MultiConditionalSplitActivity
s@MultiConditionalSplitActivity' {} Maybe [MultiConditionalBranch]
a -> MultiConditionalSplitActivity
s {$sel:branches:MultiConditionalSplitActivity' :: Maybe [MultiConditionalBranch]
branches = Maybe [MultiConditionalBranch]
a} :: MultiConditionalSplitActivity) ((Maybe [MultiConditionalBranch]
  -> f (Maybe [MultiConditionalBranch]))
 -> MultiConditionalSplitActivity
 -> f MultiConditionalSplitActivity)
-> ((Maybe [MultiConditionalBranch]
     -> f (Maybe [MultiConditionalBranch]))
    -> Maybe [MultiConditionalBranch]
    -> f (Maybe [MultiConditionalBranch]))
-> (Maybe [MultiConditionalBranch]
    -> f (Maybe [MultiConditionalBranch]))
-> MultiConditionalSplitActivity
-> f MultiConditionalSplitActivity
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [MultiConditionalBranch]
  [MultiConditionalBranch]
  [MultiConditionalBranch]
  [MultiConditionalBranch]
-> Iso
     (Maybe [MultiConditionalBranch])
     (Maybe [MultiConditionalBranch])
     (Maybe [MultiConditionalBranch])
     (Maybe [MultiConditionalBranch])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  [MultiConditionalBranch]
  [MultiConditionalBranch]
  [MultiConditionalBranch]
  [MultiConditionalBranch]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

-- | The unique identifier for the activity to perform for participants who
-- don\'t meet any of the conditions specified for other paths in the
-- activity.
multiConditionalSplitActivity_defaultActivity :: Lens.Lens' MultiConditionalSplitActivity (Prelude.Maybe Prelude.Text)
multiConditionalSplitActivity_defaultActivity :: (Maybe Text -> f (Maybe Text))
-> MultiConditionalSplitActivity -> f MultiConditionalSplitActivity
multiConditionalSplitActivity_defaultActivity = (MultiConditionalSplitActivity -> Maybe Text)
-> (MultiConditionalSplitActivity
    -> Maybe Text -> MultiConditionalSplitActivity)
-> Lens
     MultiConditionalSplitActivity
     MultiConditionalSplitActivity
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MultiConditionalSplitActivity' {Maybe Text
defaultActivity :: Maybe Text
$sel:defaultActivity:MultiConditionalSplitActivity' :: MultiConditionalSplitActivity -> Maybe Text
defaultActivity} -> Maybe Text
defaultActivity) (\s :: MultiConditionalSplitActivity
s@MultiConditionalSplitActivity' {} Maybe Text
a -> MultiConditionalSplitActivity
s {$sel:defaultActivity:MultiConditionalSplitActivity' :: Maybe Text
defaultActivity = Maybe Text
a} :: MultiConditionalSplitActivity)

instance Core.FromJSON MultiConditionalSplitActivity where
  parseJSON :: Value -> Parser MultiConditionalSplitActivity
parseJSON =
    String
-> (Object -> Parser MultiConditionalSplitActivity)
-> Value
-> Parser MultiConditionalSplitActivity
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"MultiConditionalSplitActivity"
      ( \Object
x ->
          Maybe [MultiConditionalBranch]
-> Maybe WaitTime -> Maybe Text -> MultiConditionalSplitActivity
MultiConditionalSplitActivity'
            (Maybe [MultiConditionalBranch]
 -> Maybe WaitTime -> Maybe Text -> MultiConditionalSplitActivity)
-> Parser (Maybe [MultiConditionalBranch])
-> Parser
     (Maybe WaitTime -> Maybe Text -> MultiConditionalSplitActivity)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe [MultiConditionalBranch]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Branches" Parser (Maybe (Maybe [MultiConditionalBranch]))
-> Maybe [MultiConditionalBranch]
-> Parser (Maybe [MultiConditionalBranch])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [MultiConditionalBranch]
forall a. Monoid a => a
Prelude.mempty)
            Parser
  (Maybe WaitTime -> Maybe Text -> MultiConditionalSplitActivity)
-> Parser (Maybe WaitTime)
-> Parser (Maybe Text -> MultiConditionalSplitActivity)
forall (f :: * -> *) a b. Applicative f => 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 -> MultiConditionalSplitActivity)
-> Parser (Maybe Text) -> Parser MultiConditionalSplitActivity
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
"DefaultActivity")
      )

instance
  Prelude.Hashable
    MultiConditionalSplitActivity

instance Prelude.NFData MultiConditionalSplitActivity

instance Core.ToJSON MultiConditionalSplitActivity where
  toJSON :: MultiConditionalSplitActivity -> Value
toJSON MultiConditionalSplitActivity' {Maybe [MultiConditionalBranch]
Maybe Text
Maybe WaitTime
defaultActivity :: Maybe Text
evaluationWaitTime :: Maybe WaitTime
branches :: Maybe [MultiConditionalBranch]
$sel:defaultActivity:MultiConditionalSplitActivity' :: MultiConditionalSplitActivity -> Maybe Text
$sel:evaluationWaitTime:MultiConditionalSplitActivity' :: MultiConditionalSplitActivity -> Maybe WaitTime
$sel:branches:MultiConditionalSplitActivity' :: MultiConditionalSplitActivity -> Maybe [MultiConditionalBranch]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Branches" Text -> [MultiConditionalBranch] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([MultiConditionalBranch] -> Pair)
-> Maybe [MultiConditionalBranch] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [MultiConditionalBranch]
branches,
            (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
"DefaultActivity" 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
defaultActivity
          ]
      )