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

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Pinpoint.Types.RandomSplitEntry
import qualified Amazonka.Prelude as Prelude

-- | Specifies the settings for a random split activity in a journey. This
-- type of activity randomly sends specified percentages of participants
-- down one of as many as five paths in a journey, based on conditions that
-- you specify.
--
-- /See:/ 'newRandomSplitActivity' smart constructor.
data RandomSplitActivity = RandomSplitActivity'
  { -- | The paths for the activity, including the percentage of participants to
    -- enter each path and the activity to perform for each path.
    RandomSplitActivity -> Maybe [RandomSplitEntry]
branches :: Prelude.Maybe [RandomSplitEntry]
  }
  deriving (RandomSplitActivity -> RandomSplitActivity -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RandomSplitActivity -> RandomSplitActivity -> Bool
$c/= :: RandomSplitActivity -> RandomSplitActivity -> Bool
== :: RandomSplitActivity -> RandomSplitActivity -> Bool
$c== :: RandomSplitActivity -> RandomSplitActivity -> Bool
Prelude.Eq, ReadPrec [RandomSplitActivity]
ReadPrec RandomSplitActivity
Int -> ReadS RandomSplitActivity
ReadS [RandomSplitActivity]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RandomSplitActivity]
$creadListPrec :: ReadPrec [RandomSplitActivity]
readPrec :: ReadPrec RandomSplitActivity
$creadPrec :: ReadPrec RandomSplitActivity
readList :: ReadS [RandomSplitActivity]
$creadList :: ReadS [RandomSplitActivity]
readsPrec :: Int -> ReadS RandomSplitActivity
$creadsPrec :: Int -> ReadS RandomSplitActivity
Prelude.Read, Int -> RandomSplitActivity -> ShowS
[RandomSplitActivity] -> ShowS
RandomSplitActivity -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RandomSplitActivity] -> ShowS
$cshowList :: [RandomSplitActivity] -> ShowS
show :: RandomSplitActivity -> String
$cshow :: RandomSplitActivity -> String
showsPrec :: Int -> RandomSplitActivity -> ShowS
$cshowsPrec :: Int -> RandomSplitActivity -> ShowS
Prelude.Show, forall x. Rep RandomSplitActivity x -> RandomSplitActivity
forall x. RandomSplitActivity -> Rep RandomSplitActivity x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RandomSplitActivity x -> RandomSplitActivity
$cfrom :: forall x. RandomSplitActivity -> Rep RandomSplitActivity x
Prelude.Generic)

-- |
-- Create a value of 'RandomSplitActivity' 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', 'randomSplitActivity_branches' - The paths for the activity, including the percentage of participants to
-- enter each path and the activity to perform for each path.
newRandomSplitActivity ::
  RandomSplitActivity
newRandomSplitActivity :: RandomSplitActivity
newRandomSplitActivity =
  RandomSplitActivity' {$sel:branches:RandomSplitActivity' :: Maybe [RandomSplitEntry]
branches = forall a. Maybe a
Prelude.Nothing}

-- | The paths for the activity, including the percentage of participants to
-- enter each path and the activity to perform for each path.
randomSplitActivity_branches :: Lens.Lens' RandomSplitActivity (Prelude.Maybe [RandomSplitEntry])
randomSplitActivity_branches :: Lens' RandomSplitActivity (Maybe [RandomSplitEntry])
randomSplitActivity_branches = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RandomSplitActivity' {Maybe [RandomSplitEntry]
branches :: Maybe [RandomSplitEntry]
$sel:branches:RandomSplitActivity' :: RandomSplitActivity -> Maybe [RandomSplitEntry]
branches} -> Maybe [RandomSplitEntry]
branches) (\s :: RandomSplitActivity
s@RandomSplitActivity' {} Maybe [RandomSplitEntry]
a -> RandomSplitActivity
s {$sel:branches:RandomSplitActivity' :: Maybe [RandomSplitEntry]
branches = Maybe [RandomSplitEntry]
a} :: RandomSplitActivity) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Data.FromJSON RandomSplitActivity where
  parseJSON :: Value -> Parser RandomSplitActivity
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"RandomSplitActivity"
      ( \Object
x ->
          Maybe [RandomSplitEntry] -> RandomSplitActivity
RandomSplitActivity'
            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
"Branches" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable RandomSplitActivity where
  hashWithSalt :: Int -> RandomSplitActivity -> Int
hashWithSalt Int
_salt RandomSplitActivity' {Maybe [RandomSplitEntry]
branches :: Maybe [RandomSplitEntry]
$sel:branches:RandomSplitActivity' :: RandomSplitActivity -> Maybe [RandomSplitEntry]
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [RandomSplitEntry]
branches

instance Prelude.NFData RandomSplitActivity where
  rnf :: RandomSplitActivity -> ()
rnf RandomSplitActivity' {Maybe [RandomSplitEntry]
branches :: Maybe [RandomSplitEntry]
$sel:branches:RandomSplitActivity' :: RandomSplitActivity -> Maybe [RandomSplitEntry]
..} = forall a. NFData a => a -> ()
Prelude.rnf Maybe [RandomSplitEntry]
branches

instance Data.ToJSON RandomSplitActivity where
  toJSON :: RandomSplitActivity -> Value
toJSON RandomSplitActivity' {Maybe [RandomSplitEntry]
branches :: Maybe [RandomSplitEntry]
$sel:branches:RandomSplitActivity' :: RandomSplitActivity -> Maybe [RandomSplitEntry]
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [(Key
"Branches" 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 [RandomSplitEntry]
branches]
      )