{-# 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.OnlineAbDefinition
-- 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.OnlineAbDefinition 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:/ 'newOnlineAbDefinition' smart constructor.
data OnlineAbDefinition = OnlineAbDefinition'
  { -- | The name of the variation that is the default variation that the other
    -- variations are compared to.
    OnlineAbDefinition -> 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.
    -- The traffic portion is specified in thousandths of a percent, so 20,000
    -- for a variation would allocate 20% of the experiment traffic to that
    -- variation.
    OnlineAbDefinition -> Maybe (HashMap Text Natural)
treatmentWeights :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Natural)
  }
  deriving (OnlineAbDefinition -> OnlineAbDefinition -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OnlineAbDefinition -> OnlineAbDefinition -> Bool
$c/= :: OnlineAbDefinition -> OnlineAbDefinition -> Bool
== :: OnlineAbDefinition -> OnlineAbDefinition -> Bool
$c== :: OnlineAbDefinition -> OnlineAbDefinition -> Bool
Prelude.Eq, ReadPrec [OnlineAbDefinition]
ReadPrec OnlineAbDefinition
Int -> ReadS OnlineAbDefinition
ReadS [OnlineAbDefinition]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [OnlineAbDefinition]
$creadListPrec :: ReadPrec [OnlineAbDefinition]
readPrec :: ReadPrec OnlineAbDefinition
$creadPrec :: ReadPrec OnlineAbDefinition
readList :: ReadS [OnlineAbDefinition]
$creadList :: ReadS [OnlineAbDefinition]
readsPrec :: Int -> ReadS OnlineAbDefinition
$creadsPrec :: Int -> ReadS OnlineAbDefinition
Prelude.Read, Int -> OnlineAbDefinition -> ShowS
[OnlineAbDefinition] -> ShowS
OnlineAbDefinition -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OnlineAbDefinition] -> ShowS
$cshowList :: [OnlineAbDefinition] -> ShowS
show :: OnlineAbDefinition -> String
$cshow :: OnlineAbDefinition -> String
showsPrec :: Int -> OnlineAbDefinition -> ShowS
$cshowsPrec :: Int -> OnlineAbDefinition -> ShowS
Prelude.Show, forall x. Rep OnlineAbDefinition x -> OnlineAbDefinition
forall x. OnlineAbDefinition -> Rep OnlineAbDefinition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep OnlineAbDefinition x -> OnlineAbDefinition
$cfrom :: forall x. OnlineAbDefinition -> Rep OnlineAbDefinition x
Prelude.Generic)

-- |
-- Create a value of 'OnlineAbDefinition' 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', 'onlineAbDefinition_controlTreatmentName' - The name of the variation that is the default variation that the other
-- variations are compared to.
--
-- 'treatmentWeights', 'onlineAbDefinition_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.
-- The traffic portion is specified in thousandths of a percent, so 20,000
-- for a variation would allocate 20% of the experiment traffic to that
-- variation.
newOnlineAbDefinition ::
  OnlineAbDefinition
newOnlineAbDefinition :: OnlineAbDefinition
newOnlineAbDefinition =
  OnlineAbDefinition'
    { $sel:controlTreatmentName:OnlineAbDefinition' :: Maybe Text
controlTreatmentName =
        forall a. Maybe a
Prelude.Nothing,
      $sel:treatmentWeights:OnlineAbDefinition' :: Maybe (HashMap Text Natural)
treatmentWeights = forall a. Maybe a
Prelude.Nothing
    }

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

-- | 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.
-- The traffic portion is specified in thousandths of a percent, so 20,000
-- for a variation would allocate 20% of the experiment traffic to that
-- variation.
onlineAbDefinition_treatmentWeights :: Lens.Lens' OnlineAbDefinition (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Natural))
onlineAbDefinition_treatmentWeights :: Lens' OnlineAbDefinition (Maybe (HashMap Text Natural))
onlineAbDefinition_treatmentWeights = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OnlineAbDefinition' {Maybe (HashMap Text Natural)
treatmentWeights :: Maybe (HashMap Text Natural)
$sel:treatmentWeights:OnlineAbDefinition' :: OnlineAbDefinition -> Maybe (HashMap Text Natural)
treatmentWeights} -> Maybe (HashMap Text Natural)
treatmentWeights) (\s :: OnlineAbDefinition
s@OnlineAbDefinition' {} Maybe (HashMap Text Natural)
a -> OnlineAbDefinition
s {$sel:treatmentWeights:OnlineAbDefinition' :: Maybe (HashMap Text Natural)
treatmentWeights = Maybe (HashMap Text Natural)
a} :: OnlineAbDefinition) 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 OnlineAbDefinition where
  parseJSON :: Value -> Parser OnlineAbDefinition
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"OnlineAbDefinition"
      ( \Object
x ->
          Maybe Text -> Maybe (HashMap Text Natural) -> OnlineAbDefinition
OnlineAbDefinition'
            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
"controlTreatmentName")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x
                            forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"treatmentWeights"
                            forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty
                        )
      )

instance Prelude.Hashable OnlineAbDefinition where
  hashWithSalt :: Int -> OnlineAbDefinition -> Int
hashWithSalt Int
_salt OnlineAbDefinition' {Maybe Text
Maybe (HashMap Text Natural)
treatmentWeights :: Maybe (HashMap Text Natural)
controlTreatmentName :: Maybe Text
$sel:treatmentWeights:OnlineAbDefinition' :: OnlineAbDefinition -> Maybe (HashMap Text Natural)
$sel:controlTreatmentName:OnlineAbDefinition' :: OnlineAbDefinition -> 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 OnlineAbDefinition where
  rnf :: OnlineAbDefinition -> ()
rnf OnlineAbDefinition' {Maybe Text
Maybe (HashMap Text Natural)
treatmentWeights :: Maybe (HashMap Text Natural)
controlTreatmentName :: Maybe Text
$sel:treatmentWeights:OnlineAbDefinition' :: OnlineAbDefinition -> Maybe (HashMap Text Natural)
$sel:controlTreatmentName:OnlineAbDefinition' :: OnlineAbDefinition -> 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