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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Specifies the settings for a path in a random split activity in a
-- journey.
--
-- /See:/ 'newRandomSplitEntry' smart constructor.
data RandomSplitEntry = RandomSplitEntry'
  { -- | The unique identifier for the next activity to perform, after completing
    -- the activity for the path.
    RandomSplitEntry -> Maybe Text
nextActivity :: Prelude.Maybe Prelude.Text,
    -- | The percentage of participants to send down the activity path.
    --
    -- To determine which participants are sent down each path, Amazon Pinpoint
    -- applies a probability-based algorithm to the percentages that you
    -- specify for the paths. Therefore, the actual percentage of participants
    -- who are sent down a path may not be equal to the percentage that you
    -- specify.
    RandomSplitEntry -> Maybe Int
percentage :: Prelude.Maybe Prelude.Int
  }
  deriving (RandomSplitEntry -> RandomSplitEntry -> Bool
(RandomSplitEntry -> RandomSplitEntry -> Bool)
-> (RandomSplitEntry -> RandomSplitEntry -> Bool)
-> Eq RandomSplitEntry
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RandomSplitEntry -> RandomSplitEntry -> Bool
$c/= :: RandomSplitEntry -> RandomSplitEntry -> Bool
== :: RandomSplitEntry -> RandomSplitEntry -> Bool
$c== :: RandomSplitEntry -> RandomSplitEntry -> Bool
Prelude.Eq, ReadPrec [RandomSplitEntry]
ReadPrec RandomSplitEntry
Int -> ReadS RandomSplitEntry
ReadS [RandomSplitEntry]
(Int -> ReadS RandomSplitEntry)
-> ReadS [RandomSplitEntry]
-> ReadPrec RandomSplitEntry
-> ReadPrec [RandomSplitEntry]
-> Read RandomSplitEntry
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RandomSplitEntry]
$creadListPrec :: ReadPrec [RandomSplitEntry]
readPrec :: ReadPrec RandomSplitEntry
$creadPrec :: ReadPrec RandomSplitEntry
readList :: ReadS [RandomSplitEntry]
$creadList :: ReadS [RandomSplitEntry]
readsPrec :: Int -> ReadS RandomSplitEntry
$creadsPrec :: Int -> ReadS RandomSplitEntry
Prelude.Read, Int -> RandomSplitEntry -> ShowS
[RandomSplitEntry] -> ShowS
RandomSplitEntry -> String
(Int -> RandomSplitEntry -> ShowS)
-> (RandomSplitEntry -> String)
-> ([RandomSplitEntry] -> ShowS)
-> Show RandomSplitEntry
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RandomSplitEntry] -> ShowS
$cshowList :: [RandomSplitEntry] -> ShowS
show :: RandomSplitEntry -> String
$cshow :: RandomSplitEntry -> String
showsPrec :: Int -> RandomSplitEntry -> ShowS
$cshowsPrec :: Int -> RandomSplitEntry -> ShowS
Prelude.Show, (forall x. RandomSplitEntry -> Rep RandomSplitEntry x)
-> (forall x. Rep RandomSplitEntry x -> RandomSplitEntry)
-> Generic RandomSplitEntry
forall x. Rep RandomSplitEntry x -> RandomSplitEntry
forall x. RandomSplitEntry -> Rep RandomSplitEntry x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RandomSplitEntry x -> RandomSplitEntry
$cfrom :: forall x. RandomSplitEntry -> Rep RandomSplitEntry x
Prelude.Generic)

-- |
-- Create a value of 'RandomSplitEntry' 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', 'randomSplitEntry_nextActivity' - The unique identifier for the next activity to perform, after completing
-- the activity for the path.
--
-- 'percentage', 'randomSplitEntry_percentage' - The percentage of participants to send down the activity path.
--
-- To determine which participants are sent down each path, Amazon Pinpoint
-- applies a probability-based algorithm to the percentages that you
-- specify for the paths. Therefore, the actual percentage of participants
-- who are sent down a path may not be equal to the percentage that you
-- specify.
newRandomSplitEntry ::
  RandomSplitEntry
newRandomSplitEntry :: RandomSplitEntry
newRandomSplitEntry =
  RandomSplitEntry' :: Maybe Text -> Maybe Int -> RandomSplitEntry
RandomSplitEntry'
    { $sel:nextActivity:RandomSplitEntry' :: Maybe Text
nextActivity = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:percentage:RandomSplitEntry' :: Maybe Int
percentage = Maybe Int
forall a. Maybe a
Prelude.Nothing
    }

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

-- | The percentage of participants to send down the activity path.
--
-- To determine which participants are sent down each path, Amazon Pinpoint
-- applies a probability-based algorithm to the percentages that you
-- specify for the paths. Therefore, the actual percentage of participants
-- who are sent down a path may not be equal to the percentage that you
-- specify.
randomSplitEntry_percentage :: Lens.Lens' RandomSplitEntry (Prelude.Maybe Prelude.Int)
randomSplitEntry_percentage :: (Maybe Int -> f (Maybe Int))
-> RandomSplitEntry -> f RandomSplitEntry
randomSplitEntry_percentage = (RandomSplitEntry -> Maybe Int)
-> (RandomSplitEntry -> Maybe Int -> RandomSplitEntry)
-> Lens RandomSplitEntry RandomSplitEntry (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RandomSplitEntry' {Maybe Int
percentage :: Maybe Int
$sel:percentage:RandomSplitEntry' :: RandomSplitEntry -> Maybe Int
percentage} -> Maybe Int
percentage) (\s :: RandomSplitEntry
s@RandomSplitEntry' {} Maybe Int
a -> RandomSplitEntry
s {$sel:percentage:RandomSplitEntry' :: Maybe Int
percentage = Maybe Int
a} :: RandomSplitEntry)

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

instance Prelude.Hashable RandomSplitEntry

instance Prelude.NFData RandomSplitEntry

instance Core.ToJSON RandomSplitEntry where
  toJSON :: RandomSplitEntry -> Value
toJSON RandomSplitEntry' {Maybe Int
Maybe Text
percentage :: Maybe Int
nextActivity :: Maybe Text
$sel:percentage:RandomSplitEntry' :: RandomSplitEntry -> Maybe Int
$sel:nextActivity:RandomSplitEntry' :: RandomSplitEntry -> 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
"Percentage" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Int -> Pair) -> Maybe Int -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Int
percentage
          ]
      )