{-# 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.Evidently.Types.OnlineAbConfig
-- 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.Evidently.Types.OnlineAbConfig 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

-- | A structure that contains the configuration of which variation to use as
-- the \"control\" version. The \"control\" version is used for comparison
-- with other variations. This structure also specifies how much experiment
-- traffic is allocated to each variation.
--
-- /See:/ 'newOnlineAbConfig' smart constructor.
data OnlineAbConfig = OnlineAbConfig'
  { -- | The name of the variation that is to be the default variation that the
    -- other variations are compared to.
    OnlineAbConfig -> Maybe Text
controlTreatmentName :: Prelude.Maybe Prelude.Text,
    -- | A set of key-value pairs. The keys are variation names, and the values
    -- are the portion of experiment traffic to be assigned to that variation.
    -- Specify the traffic portion in thousandths of a percent, so 20,000 for a
    -- variation would allocate 20% of the experiment traffic to that
    -- variation.
    OnlineAbConfig -> Maybe (HashMap Text Natural)
treatmentWeights :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Natural)
  }
  deriving (OnlineAbConfig -> OnlineAbConfig -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OnlineAbConfig -> OnlineAbConfig -> Bool
$c/= :: OnlineAbConfig -> OnlineAbConfig -> Bool
== :: OnlineAbConfig -> OnlineAbConfig -> Bool
$c== :: OnlineAbConfig -> OnlineAbConfig -> Bool
Prelude.Eq, ReadPrec [OnlineAbConfig]
ReadPrec OnlineAbConfig
Int -> ReadS OnlineAbConfig
ReadS [OnlineAbConfig]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [OnlineAbConfig]
$creadListPrec :: ReadPrec [OnlineAbConfig]
readPrec :: ReadPrec OnlineAbConfig
$creadPrec :: ReadPrec OnlineAbConfig
readList :: ReadS [OnlineAbConfig]
$creadList :: ReadS [OnlineAbConfig]
readsPrec :: Int -> ReadS OnlineAbConfig
$creadsPrec :: Int -> ReadS OnlineAbConfig
Prelude.Read, Int -> OnlineAbConfig -> ShowS
[OnlineAbConfig] -> ShowS
OnlineAbConfig -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OnlineAbConfig] -> ShowS
$cshowList :: [OnlineAbConfig] -> ShowS
show :: OnlineAbConfig -> String
$cshow :: OnlineAbConfig -> String
showsPrec :: Int -> OnlineAbConfig -> ShowS
$cshowsPrec :: Int -> OnlineAbConfig -> ShowS
Prelude.Show, forall x. Rep OnlineAbConfig x -> OnlineAbConfig
forall x. OnlineAbConfig -> Rep OnlineAbConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep OnlineAbConfig x -> OnlineAbConfig
$cfrom :: forall x. OnlineAbConfig -> Rep OnlineAbConfig x
Prelude.Generic)

-- |
-- Create a value of 'OnlineAbConfig' 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:
--
-- 'controlTreatmentName', 'onlineAbConfig_controlTreatmentName' - The name of the variation that is to be the default variation that the
-- other variations are compared to.
--
-- 'treatmentWeights', 'onlineAbConfig_treatmentWeights' - A set of key-value pairs. The keys are variation names, and the values
-- are the portion of experiment traffic to be assigned to that variation.
-- Specify the traffic portion in thousandths of a percent, so 20,000 for a
-- variation would allocate 20% of the experiment traffic to that
-- variation.
newOnlineAbConfig ::
  OnlineAbConfig
newOnlineAbConfig :: OnlineAbConfig
newOnlineAbConfig =
  OnlineAbConfig'
    { $sel:controlTreatmentName:OnlineAbConfig' :: Maybe Text
controlTreatmentName =
        forall a. Maybe a
Prelude.Nothing,
      $sel:treatmentWeights:OnlineAbConfig' :: Maybe (HashMap Text Natural)
treatmentWeights = forall a. Maybe a
Prelude.Nothing
    }

-- | The name of the variation that is to be the default variation that the
-- other variations are compared to.
onlineAbConfig_controlTreatmentName :: Lens.Lens' OnlineAbConfig (Prelude.Maybe Prelude.Text)
onlineAbConfig_controlTreatmentName :: Lens' OnlineAbConfig (Maybe Text)
onlineAbConfig_controlTreatmentName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OnlineAbConfig' {Maybe Text
controlTreatmentName :: Maybe Text
$sel:controlTreatmentName:OnlineAbConfig' :: OnlineAbConfig -> Maybe Text
controlTreatmentName} -> Maybe Text
controlTreatmentName) (\s :: OnlineAbConfig
s@OnlineAbConfig' {} Maybe Text
a -> OnlineAbConfig
s {$sel:controlTreatmentName:OnlineAbConfig' :: Maybe Text
controlTreatmentName = Maybe Text
a} :: OnlineAbConfig)

-- | A set of key-value pairs. The keys are variation names, and the values
-- are the portion of experiment traffic to be assigned to that variation.
-- Specify the traffic portion in thousandths of a percent, so 20,000 for a
-- variation would allocate 20% of the experiment traffic to that
-- variation.
onlineAbConfig_treatmentWeights :: Lens.Lens' OnlineAbConfig (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Natural))
onlineAbConfig_treatmentWeights :: Lens' OnlineAbConfig (Maybe (HashMap Text Natural))
onlineAbConfig_treatmentWeights = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OnlineAbConfig' {Maybe (HashMap Text Natural)
treatmentWeights :: Maybe (HashMap Text Natural)
$sel:treatmentWeights:OnlineAbConfig' :: OnlineAbConfig -> Maybe (HashMap Text Natural)
treatmentWeights} -> Maybe (HashMap Text Natural)
treatmentWeights) (\s :: OnlineAbConfig
s@OnlineAbConfig' {} Maybe (HashMap Text Natural)
a -> OnlineAbConfig
s {$sel:treatmentWeights:OnlineAbConfig' :: Maybe (HashMap Text Natural)
treatmentWeights = Maybe (HashMap Text Natural)
a} :: OnlineAbConfig) 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 Prelude.Hashable OnlineAbConfig where
  hashWithSalt :: Int -> OnlineAbConfig -> Int
hashWithSalt Int
_salt OnlineAbConfig' {Maybe Text
Maybe (HashMap Text Natural)
treatmentWeights :: Maybe (HashMap Text Natural)
controlTreatmentName :: Maybe Text
$sel:treatmentWeights:OnlineAbConfig' :: OnlineAbConfig -> Maybe (HashMap Text Natural)
$sel:controlTreatmentName:OnlineAbConfig' :: OnlineAbConfig -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
controlTreatmentName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text Natural)
treatmentWeights

instance Prelude.NFData OnlineAbConfig where
  rnf :: OnlineAbConfig -> ()
rnf OnlineAbConfig' {Maybe Text
Maybe (HashMap Text Natural)
treatmentWeights :: Maybe (HashMap Text Natural)
controlTreatmentName :: Maybe Text
$sel:treatmentWeights:OnlineAbConfig' :: OnlineAbConfig -> Maybe (HashMap Text Natural)
$sel:controlTreatmentName:OnlineAbConfig' :: OnlineAbConfig -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
controlTreatmentName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text Natural)
treatmentWeights

instance Data.ToJSON OnlineAbConfig where
  toJSON :: OnlineAbConfig -> Value
toJSON OnlineAbConfig' {Maybe Text
Maybe (HashMap Text Natural)
treatmentWeights :: Maybe (HashMap Text Natural)
controlTreatmentName :: Maybe Text
$sel:treatmentWeights:OnlineAbConfig' :: OnlineAbConfig -> Maybe (HashMap Text Natural)
$sel:controlTreatmentName:OnlineAbConfig' :: OnlineAbConfig -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"controlTreatmentName" 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
controlTreatmentName,
            (Key
"treatmentWeights" 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 (HashMap Text Natural)
treatmentWeights
          ]
      )