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

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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]
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
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. 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'
    { $sel:nextActivity:HoldoutActivity' :: Maybe Text
nextActivity = 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 :: Lens' HoldoutActivity (Maybe Text)
holdoutActivity_nextActivity = 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 :: Lens' HoldoutActivity Int
holdoutActivity_percentage = 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 Data.FromJSON HoldoutActivity where
  parseJSON :: Value -> Parser HoldoutActivity
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"HoldoutActivity"
      ( \Object
x ->
          Maybe Text -> Int -> HoldoutActivity
HoldoutActivity'
            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
"NextActivity")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Percentage")
      )

instance Prelude.Hashable HoldoutActivity where
  hashWithSalt :: Int -> HoldoutActivity -> Int
hashWithSalt Int
_salt HoldoutActivity' {Int
Maybe Text
percentage :: Int
nextActivity :: Maybe Text
$sel:percentage:HoldoutActivity' :: HoldoutActivity -> Int
$sel:nextActivity:HoldoutActivity' :: HoldoutActivity -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
nextActivity
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Int
percentage

instance Prelude.NFData HoldoutActivity where
  rnf :: HoldoutActivity -> ()
rnf HoldoutActivity' {Int
Maybe Text
percentage :: Int
nextActivity :: Maybe Text
$sel:percentage:HoldoutActivity' :: HoldoutActivity -> Int
$sel:nextActivity:HoldoutActivity' :: HoldoutActivity -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
nextActivity
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
percentage

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"NextActivity" 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 Text
nextActivity,
            forall a. a -> Maybe a
Prelude.Just (Key
"Percentage" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Int
percentage)
          ]
      )