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

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

-- | Specifies a condition to evaluate for an activity path in a journey.
--
-- /See:/ 'newMultiConditionalBranch' smart constructor.
data MultiConditionalBranch = MultiConditionalBranch'
  { -- | The unique identifier for the next activity to perform, after completing
    -- the activity for the path.
    MultiConditionalBranch -> Maybe Text
nextActivity :: Prelude.Maybe Prelude.Text,
    -- | The condition to evaluate for the activity path.
    MultiConditionalBranch -> Maybe SimpleCondition
condition :: Prelude.Maybe SimpleCondition
  }
  deriving (MultiConditionalBranch -> MultiConditionalBranch -> Bool
(MultiConditionalBranch -> MultiConditionalBranch -> Bool)
-> (MultiConditionalBranch -> MultiConditionalBranch -> Bool)
-> Eq MultiConditionalBranch
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MultiConditionalBranch -> MultiConditionalBranch -> Bool
$c/= :: MultiConditionalBranch -> MultiConditionalBranch -> Bool
== :: MultiConditionalBranch -> MultiConditionalBranch -> Bool
$c== :: MultiConditionalBranch -> MultiConditionalBranch -> Bool
Prelude.Eq, ReadPrec [MultiConditionalBranch]
ReadPrec MultiConditionalBranch
Int -> ReadS MultiConditionalBranch
ReadS [MultiConditionalBranch]
(Int -> ReadS MultiConditionalBranch)
-> ReadS [MultiConditionalBranch]
-> ReadPrec MultiConditionalBranch
-> ReadPrec [MultiConditionalBranch]
-> Read MultiConditionalBranch
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MultiConditionalBranch]
$creadListPrec :: ReadPrec [MultiConditionalBranch]
readPrec :: ReadPrec MultiConditionalBranch
$creadPrec :: ReadPrec MultiConditionalBranch
readList :: ReadS [MultiConditionalBranch]
$creadList :: ReadS [MultiConditionalBranch]
readsPrec :: Int -> ReadS MultiConditionalBranch
$creadsPrec :: Int -> ReadS MultiConditionalBranch
Prelude.Read, Int -> MultiConditionalBranch -> ShowS
[MultiConditionalBranch] -> ShowS
MultiConditionalBranch -> String
(Int -> MultiConditionalBranch -> ShowS)
-> (MultiConditionalBranch -> String)
-> ([MultiConditionalBranch] -> ShowS)
-> Show MultiConditionalBranch
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MultiConditionalBranch] -> ShowS
$cshowList :: [MultiConditionalBranch] -> ShowS
show :: MultiConditionalBranch -> String
$cshow :: MultiConditionalBranch -> String
showsPrec :: Int -> MultiConditionalBranch -> ShowS
$cshowsPrec :: Int -> MultiConditionalBranch -> ShowS
Prelude.Show, (forall x. MultiConditionalBranch -> Rep MultiConditionalBranch x)
-> (forall x.
    Rep MultiConditionalBranch x -> MultiConditionalBranch)
-> Generic MultiConditionalBranch
forall x. Rep MultiConditionalBranch x -> MultiConditionalBranch
forall x. MultiConditionalBranch -> Rep MultiConditionalBranch x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MultiConditionalBranch x -> MultiConditionalBranch
$cfrom :: forall x. MultiConditionalBranch -> Rep MultiConditionalBranch x
Prelude.Generic)

-- |
-- Create a value of 'MultiConditionalBranch' 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:
--
-- 'nextActivity', 'multiConditionalBranch_nextActivity' - The unique identifier for the next activity to perform, after completing
-- the activity for the path.
--
-- 'condition', 'multiConditionalBranch_condition' - The condition to evaluate for the activity path.
newMultiConditionalBranch ::
  MultiConditionalBranch
newMultiConditionalBranch :: MultiConditionalBranch
newMultiConditionalBranch =
  MultiConditionalBranch' :: Maybe Text -> Maybe SimpleCondition -> MultiConditionalBranch
MultiConditionalBranch'
    { $sel:nextActivity:MultiConditionalBranch' :: Maybe Text
nextActivity =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:condition:MultiConditionalBranch' :: Maybe SimpleCondition
condition = Maybe SimpleCondition
forall a. Maybe a
Prelude.Nothing
    }

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

-- | The condition to evaluate for the activity path.
multiConditionalBranch_condition :: Lens.Lens' MultiConditionalBranch (Prelude.Maybe SimpleCondition)
multiConditionalBranch_condition :: (Maybe SimpleCondition -> f (Maybe SimpleCondition))
-> MultiConditionalBranch -> f MultiConditionalBranch
multiConditionalBranch_condition = (MultiConditionalBranch -> Maybe SimpleCondition)
-> (MultiConditionalBranch
    -> Maybe SimpleCondition -> MultiConditionalBranch)
-> Lens
     MultiConditionalBranch
     MultiConditionalBranch
     (Maybe SimpleCondition)
     (Maybe SimpleCondition)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MultiConditionalBranch' {Maybe SimpleCondition
condition :: Maybe SimpleCondition
$sel:condition:MultiConditionalBranch' :: MultiConditionalBranch -> Maybe SimpleCondition
condition} -> Maybe SimpleCondition
condition) (\s :: MultiConditionalBranch
s@MultiConditionalBranch' {} Maybe SimpleCondition
a -> MultiConditionalBranch
s {$sel:condition:MultiConditionalBranch' :: Maybe SimpleCondition
condition = Maybe SimpleCondition
a} :: MultiConditionalBranch)

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

instance Prelude.Hashable MultiConditionalBranch

instance Prelude.NFData MultiConditionalBranch

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