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

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

-- | Specifies the settings for a holdout activity in a journey. This type of
-- activity stops a journey for a specified percentage of participants.
--
-- /See:/ 'newHoldoutActivity' smart constructor.
data HoldoutActivity = HoldoutActivity'
  { -- | The unique identifier for the next activity to perform, after performing
    -- the holdout activity.
    HoldoutActivity -> Maybe Text
nextActivity :: Prelude.Maybe Prelude.Text,
    -- | The percentage of participants who shouldn\'t continue the journey.
    --
    -- To determine which participants are held out, Amazon Pinpoint applies a
    -- probability-based algorithm to the percentage that you specify.
    -- Therefore, the actual percentage of participants who are held out may
    -- not be equal to the percentage that you specify.
    HoldoutActivity -> Int
percentage :: Prelude.Int
  }
  deriving (HoldoutActivity -> HoldoutActivity -> Bool
(HoldoutActivity -> HoldoutActivity -> Bool)
-> (HoldoutActivity -> HoldoutActivity -> Bool)
-> Eq HoldoutActivity
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HoldoutActivity -> HoldoutActivity -> Bool
$c/= :: HoldoutActivity -> HoldoutActivity -> Bool
== :: HoldoutActivity -> HoldoutActivity -> Bool
$c== :: HoldoutActivity -> HoldoutActivity -> Bool
Prelude.Eq, ReadPrec [HoldoutActivity]
ReadPrec HoldoutActivity
Int -> ReadS HoldoutActivity
ReadS [HoldoutActivity]
(Int -> ReadS HoldoutActivity)
-> ReadS [HoldoutActivity]
-> ReadPrec HoldoutActivity
-> ReadPrec [HoldoutActivity]
-> Read HoldoutActivity
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [HoldoutActivity]
$creadListPrec :: ReadPrec [HoldoutActivity]
readPrec :: ReadPrec HoldoutActivity
$creadPrec :: ReadPrec HoldoutActivity
readList :: ReadS [HoldoutActivity]
$creadList :: ReadS [HoldoutActivity]
readsPrec :: Int -> ReadS HoldoutActivity
$creadsPrec :: Int -> ReadS HoldoutActivity
Prelude.Read, Int -> HoldoutActivity -> ShowS
[HoldoutActivity] -> ShowS
HoldoutActivity -> String
(Int -> HoldoutActivity -> ShowS)
-> (HoldoutActivity -> String)
-> ([HoldoutActivity] -> ShowS)
-> Show HoldoutActivity
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HoldoutActivity] -> ShowS
$cshowList :: [HoldoutActivity] -> ShowS
show :: HoldoutActivity -> String
$cshow :: HoldoutActivity -> String
showsPrec :: Int -> HoldoutActivity -> ShowS
$cshowsPrec :: Int -> HoldoutActivity -> ShowS
Prelude.Show, (forall x. HoldoutActivity -> Rep HoldoutActivity x)
-> (forall x. Rep HoldoutActivity x -> HoldoutActivity)
-> Generic HoldoutActivity
forall x. Rep HoldoutActivity x -> HoldoutActivity
forall x. HoldoutActivity -> Rep HoldoutActivity x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep HoldoutActivity x -> HoldoutActivity
$cfrom :: forall x. HoldoutActivity -> Rep HoldoutActivity x
Prelude.Generic)

-- |
-- Create a value of 'HoldoutActivity' 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', 'holdoutActivity_nextActivity' - The unique identifier for the next activity to perform, after performing
-- the holdout activity.
--
-- 'percentage', 'holdoutActivity_percentage' - The percentage of participants who shouldn\'t continue the journey.
--
-- To determine which participants are held out, Amazon Pinpoint applies a
-- probability-based algorithm to the percentage that you specify.
-- Therefore, the actual percentage of participants who are held out may
-- not be equal to the percentage that you specify.
newHoldoutActivity ::
  -- | 'percentage'
  Prelude.Int ->
  HoldoutActivity
newHoldoutActivity :: Int -> HoldoutActivity
newHoldoutActivity Int
pPercentage_ =
  HoldoutActivity' :: Maybe Text -> Int -> HoldoutActivity
HoldoutActivity'
    { $sel:nextActivity:HoldoutActivity' :: Maybe Text
nextActivity = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:percentage:HoldoutActivity' :: Int
percentage = Int
pPercentage_
    }

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

-- | The percentage of participants who shouldn\'t continue the journey.
--
-- To determine which participants are held out, Amazon Pinpoint applies a
-- probability-based algorithm to the percentage that you specify.
-- Therefore, the actual percentage of participants who are held out may
-- not be equal to the percentage that you specify.
holdoutActivity_percentage :: Lens.Lens' HoldoutActivity Prelude.Int
holdoutActivity_percentage :: (Int -> f Int) -> HoldoutActivity -> f HoldoutActivity
holdoutActivity_percentage = (HoldoutActivity -> Int)
-> (HoldoutActivity -> Int -> HoldoutActivity)
-> Lens HoldoutActivity HoldoutActivity Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HoldoutActivity' {Int
percentage :: Int
$sel:percentage:HoldoutActivity' :: HoldoutActivity -> Int
percentage} -> Int
percentage) (\s :: HoldoutActivity
s@HoldoutActivity' {} Int
a -> HoldoutActivity
s {$sel:percentage:HoldoutActivity' :: Int
percentage = Int
a} :: HoldoutActivity)

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

instance Prelude.Hashable HoldoutActivity

instance Prelude.NFData HoldoutActivity

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