{-# 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.VariableValue
-- 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.VariableValue 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

-- | The value assigned to a feature variation. This structure must contain
-- exactly one field. It can be @boolValue@, @doubleValue@, @longValue@, or
-- @stringValue@.
--
-- /See:/ 'newVariableValue' smart constructor.
data VariableValue = VariableValue'
  { -- | If this feature uses the Boolean variation type, this field contains the
    -- Boolean value of this variation.
    VariableValue -> Maybe Bool
boolValue :: Prelude.Maybe Prelude.Bool,
    -- | If this feature uses the double integer variation type, this field
    -- contains the double integer value of this variation.
    VariableValue -> Maybe Double
doubleValue :: Prelude.Maybe Prelude.Double,
    -- | If this feature uses the long variation type, this field contains the
    -- long value of this variation.
    VariableValue -> Maybe Integer
longValue :: Prelude.Maybe Prelude.Integer,
    -- | If this feature uses the string variation type, this field contains the
    -- string value of this variation.
    VariableValue -> Maybe Text
stringValue :: Prelude.Maybe Prelude.Text
  }
  deriving (VariableValue -> VariableValue -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: VariableValue -> VariableValue -> Bool
$c/= :: VariableValue -> VariableValue -> Bool
== :: VariableValue -> VariableValue -> Bool
$c== :: VariableValue -> VariableValue -> Bool
Prelude.Eq, ReadPrec [VariableValue]
ReadPrec VariableValue
Int -> ReadS VariableValue
ReadS [VariableValue]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [VariableValue]
$creadListPrec :: ReadPrec [VariableValue]
readPrec :: ReadPrec VariableValue
$creadPrec :: ReadPrec VariableValue
readList :: ReadS [VariableValue]
$creadList :: ReadS [VariableValue]
readsPrec :: Int -> ReadS VariableValue
$creadsPrec :: Int -> ReadS VariableValue
Prelude.Read, Int -> VariableValue -> ShowS
[VariableValue] -> ShowS
VariableValue -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [VariableValue] -> ShowS
$cshowList :: [VariableValue] -> ShowS
show :: VariableValue -> String
$cshow :: VariableValue -> String
showsPrec :: Int -> VariableValue -> ShowS
$cshowsPrec :: Int -> VariableValue -> ShowS
Prelude.Show, forall x. Rep VariableValue x -> VariableValue
forall x. VariableValue -> Rep VariableValue x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep VariableValue x -> VariableValue
$cfrom :: forall x. VariableValue -> Rep VariableValue x
Prelude.Generic)

-- |
-- Create a value of 'VariableValue' 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:
--
-- 'boolValue', 'variableValue_boolValue' - If this feature uses the Boolean variation type, this field contains the
-- Boolean value of this variation.
--
-- 'doubleValue', 'variableValue_doubleValue' - If this feature uses the double integer variation type, this field
-- contains the double integer value of this variation.
--
-- 'longValue', 'variableValue_longValue' - If this feature uses the long variation type, this field contains the
-- long value of this variation.
--
-- 'stringValue', 'variableValue_stringValue' - If this feature uses the string variation type, this field contains the
-- string value of this variation.
newVariableValue ::
  VariableValue
newVariableValue :: VariableValue
newVariableValue =
  VariableValue'
    { $sel:boolValue:VariableValue' :: Maybe Bool
boolValue = forall a. Maybe a
Prelude.Nothing,
      $sel:doubleValue:VariableValue' :: Maybe Double
doubleValue = forall a. Maybe a
Prelude.Nothing,
      $sel:longValue:VariableValue' :: Maybe Integer
longValue = forall a. Maybe a
Prelude.Nothing,
      $sel:stringValue:VariableValue' :: Maybe Text
stringValue = forall a. Maybe a
Prelude.Nothing
    }

-- | If this feature uses the Boolean variation type, this field contains the
-- Boolean value of this variation.
variableValue_boolValue :: Lens.Lens' VariableValue (Prelude.Maybe Prelude.Bool)
variableValue_boolValue :: Lens' VariableValue (Maybe Bool)
variableValue_boolValue = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\VariableValue' {Maybe Bool
boolValue :: Maybe Bool
$sel:boolValue:VariableValue' :: VariableValue -> Maybe Bool
boolValue} -> Maybe Bool
boolValue) (\s :: VariableValue
s@VariableValue' {} Maybe Bool
a -> VariableValue
s {$sel:boolValue:VariableValue' :: Maybe Bool
boolValue = Maybe Bool
a} :: VariableValue)

-- | If this feature uses the double integer variation type, this field
-- contains the double integer value of this variation.
variableValue_doubleValue :: Lens.Lens' VariableValue (Prelude.Maybe Prelude.Double)
variableValue_doubleValue :: Lens' VariableValue (Maybe Double)
variableValue_doubleValue = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\VariableValue' {Maybe Double
doubleValue :: Maybe Double
$sel:doubleValue:VariableValue' :: VariableValue -> Maybe Double
doubleValue} -> Maybe Double
doubleValue) (\s :: VariableValue
s@VariableValue' {} Maybe Double
a -> VariableValue
s {$sel:doubleValue:VariableValue' :: Maybe Double
doubleValue = Maybe Double
a} :: VariableValue)

-- | If this feature uses the long variation type, this field contains the
-- long value of this variation.
variableValue_longValue :: Lens.Lens' VariableValue (Prelude.Maybe Prelude.Integer)
variableValue_longValue :: Lens' VariableValue (Maybe Integer)
variableValue_longValue = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\VariableValue' {Maybe Integer
longValue :: Maybe Integer
$sel:longValue:VariableValue' :: VariableValue -> Maybe Integer
longValue} -> Maybe Integer
longValue) (\s :: VariableValue
s@VariableValue' {} Maybe Integer
a -> VariableValue
s {$sel:longValue:VariableValue' :: Maybe Integer
longValue = Maybe Integer
a} :: VariableValue)

-- | If this feature uses the string variation type, this field contains the
-- string value of this variation.
variableValue_stringValue :: Lens.Lens' VariableValue (Prelude.Maybe Prelude.Text)
variableValue_stringValue :: Lens' VariableValue (Maybe Text)
variableValue_stringValue = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\VariableValue' {Maybe Text
stringValue :: Maybe Text
$sel:stringValue:VariableValue' :: VariableValue -> Maybe Text
stringValue} -> Maybe Text
stringValue) (\s :: VariableValue
s@VariableValue' {} Maybe Text
a -> VariableValue
s {$sel:stringValue:VariableValue' :: Maybe Text
stringValue = Maybe Text
a} :: VariableValue)

instance Data.FromJSON VariableValue where
  parseJSON :: Value -> Parser VariableValue
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"VariableValue"
      ( \Object
x ->
          Maybe Bool
-> Maybe Double -> Maybe Integer -> Maybe Text -> VariableValue
VariableValue'
            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
"boolValue")
            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
"doubleValue")
            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
"longValue")
            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
"stringValue")
      )

instance Prelude.Hashable VariableValue where
  hashWithSalt :: Int -> VariableValue -> Int
hashWithSalt Int
_salt VariableValue' {Maybe Bool
Maybe Double
Maybe Integer
Maybe Text
stringValue :: Maybe Text
longValue :: Maybe Integer
doubleValue :: Maybe Double
boolValue :: Maybe Bool
$sel:stringValue:VariableValue' :: VariableValue -> Maybe Text
$sel:longValue:VariableValue' :: VariableValue -> Maybe Integer
$sel:doubleValue:VariableValue' :: VariableValue -> Maybe Double
$sel:boolValue:VariableValue' :: VariableValue -> Maybe Bool
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
boolValue
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Double
doubleValue
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Integer
longValue
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
stringValue

instance Prelude.NFData VariableValue where
  rnf :: VariableValue -> ()
rnf VariableValue' {Maybe Bool
Maybe Double
Maybe Integer
Maybe Text
stringValue :: Maybe Text
longValue :: Maybe Integer
doubleValue :: Maybe Double
boolValue :: Maybe Bool
$sel:stringValue:VariableValue' :: VariableValue -> Maybe Text
$sel:longValue:VariableValue' :: VariableValue -> Maybe Integer
$sel:doubleValue:VariableValue' :: VariableValue -> Maybe Double
$sel:boolValue:VariableValue' :: VariableValue -> Maybe Bool
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
boolValue
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Double
doubleValue
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Integer
longValue
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
stringValue

instance Data.ToJSON VariableValue where
  toJSON :: VariableValue -> Value
toJSON VariableValue' {Maybe Bool
Maybe Double
Maybe Integer
Maybe Text
stringValue :: Maybe Text
longValue :: Maybe Integer
doubleValue :: Maybe Double
boolValue :: Maybe Bool
$sel:stringValue:VariableValue' :: VariableValue -> Maybe Text
$sel:longValue:VariableValue' :: VariableValue -> Maybe Integer
$sel:doubleValue:VariableValue' :: VariableValue -> Maybe Double
$sel:boolValue:VariableValue' :: VariableValue -> Maybe Bool
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"boolValue" 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 Bool
boolValue,
            (Key
"doubleValue" 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 Double
doubleValue,
            (Key
"longValue" 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 Integer
longValue,
            (Key
"stringValue" 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
stringValue
          ]
      )