{-# 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.SageMaker.Types.TrialComponentParameterValue
-- 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.SageMaker.Types.TrialComponentParameterValue where

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

-- | The value of a hyperparameter. Only one of @NumberValue@ or
-- @StringValue@ can be specified.
--
-- This object is specified in the CreateTrialComponent request.
--
-- /See:/ 'newTrialComponentParameterValue' smart constructor.
data TrialComponentParameterValue = TrialComponentParameterValue'
  { -- | The numeric value of a numeric hyperparameter. If you specify a value
    -- for this parameter, you can\'t specify the @StringValue@ parameter.
    TrialComponentParameterValue -> Maybe Double
numberValue :: Prelude.Maybe Prelude.Double,
    -- | The string value of a categorical hyperparameter. If you specify a value
    -- for this parameter, you can\'t specify the @NumberValue@ parameter.
    TrialComponentParameterValue -> Maybe Text
stringValue :: Prelude.Maybe Prelude.Text
  }
  deriving (TrialComponentParameterValue
-> TrialComponentParameterValue -> Bool
(TrialComponentParameterValue
 -> TrialComponentParameterValue -> Bool)
-> (TrialComponentParameterValue
    -> TrialComponentParameterValue -> Bool)
-> Eq TrialComponentParameterValue
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TrialComponentParameterValue
-> TrialComponentParameterValue -> Bool
$c/= :: TrialComponentParameterValue
-> TrialComponentParameterValue -> Bool
== :: TrialComponentParameterValue
-> TrialComponentParameterValue -> Bool
$c== :: TrialComponentParameterValue
-> TrialComponentParameterValue -> Bool
Prelude.Eq, ReadPrec [TrialComponentParameterValue]
ReadPrec TrialComponentParameterValue
Int -> ReadS TrialComponentParameterValue
ReadS [TrialComponentParameterValue]
(Int -> ReadS TrialComponentParameterValue)
-> ReadS [TrialComponentParameterValue]
-> ReadPrec TrialComponentParameterValue
-> ReadPrec [TrialComponentParameterValue]
-> Read TrialComponentParameterValue
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TrialComponentParameterValue]
$creadListPrec :: ReadPrec [TrialComponentParameterValue]
readPrec :: ReadPrec TrialComponentParameterValue
$creadPrec :: ReadPrec TrialComponentParameterValue
readList :: ReadS [TrialComponentParameterValue]
$creadList :: ReadS [TrialComponentParameterValue]
readsPrec :: Int -> ReadS TrialComponentParameterValue
$creadsPrec :: Int -> ReadS TrialComponentParameterValue
Prelude.Read, Int -> TrialComponentParameterValue -> ShowS
[TrialComponentParameterValue] -> ShowS
TrialComponentParameterValue -> String
(Int -> TrialComponentParameterValue -> ShowS)
-> (TrialComponentParameterValue -> String)
-> ([TrialComponentParameterValue] -> ShowS)
-> Show TrialComponentParameterValue
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TrialComponentParameterValue] -> ShowS
$cshowList :: [TrialComponentParameterValue] -> ShowS
show :: TrialComponentParameterValue -> String
$cshow :: TrialComponentParameterValue -> String
showsPrec :: Int -> TrialComponentParameterValue -> ShowS
$cshowsPrec :: Int -> TrialComponentParameterValue -> ShowS
Prelude.Show, (forall x.
 TrialComponentParameterValue -> Rep TrialComponentParameterValue x)
-> (forall x.
    Rep TrialComponentParameterValue x -> TrialComponentParameterValue)
-> Generic TrialComponentParameterValue
forall x.
Rep TrialComponentParameterValue x -> TrialComponentParameterValue
forall x.
TrialComponentParameterValue -> Rep TrialComponentParameterValue x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep TrialComponentParameterValue x -> TrialComponentParameterValue
$cfrom :: forall x.
TrialComponentParameterValue -> Rep TrialComponentParameterValue x
Prelude.Generic)

-- |
-- Create a value of 'TrialComponentParameterValue' 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:
--
-- 'numberValue', 'trialComponentParameterValue_numberValue' - The numeric value of a numeric hyperparameter. If you specify a value
-- for this parameter, you can\'t specify the @StringValue@ parameter.
--
-- 'stringValue', 'trialComponentParameterValue_stringValue' - The string value of a categorical hyperparameter. If you specify a value
-- for this parameter, you can\'t specify the @NumberValue@ parameter.
newTrialComponentParameterValue ::
  TrialComponentParameterValue
newTrialComponentParameterValue :: TrialComponentParameterValue
newTrialComponentParameterValue =
  TrialComponentParameterValue' :: Maybe Double -> Maybe Text -> TrialComponentParameterValue
TrialComponentParameterValue'
    { $sel:numberValue:TrialComponentParameterValue' :: Maybe Double
numberValue =
        Maybe Double
forall a. Maybe a
Prelude.Nothing,
      $sel:stringValue:TrialComponentParameterValue' :: Maybe Text
stringValue = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The numeric value of a numeric hyperparameter. If you specify a value
-- for this parameter, you can\'t specify the @StringValue@ parameter.
trialComponentParameterValue_numberValue :: Lens.Lens' TrialComponentParameterValue (Prelude.Maybe Prelude.Double)
trialComponentParameterValue_numberValue :: (Maybe Double -> f (Maybe Double))
-> TrialComponentParameterValue -> f TrialComponentParameterValue
trialComponentParameterValue_numberValue = (TrialComponentParameterValue -> Maybe Double)
-> (TrialComponentParameterValue
    -> Maybe Double -> TrialComponentParameterValue)
-> Lens
     TrialComponentParameterValue
     TrialComponentParameterValue
     (Maybe Double)
     (Maybe Double)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TrialComponentParameterValue' {Maybe Double
numberValue :: Maybe Double
$sel:numberValue:TrialComponentParameterValue' :: TrialComponentParameterValue -> Maybe Double
numberValue} -> Maybe Double
numberValue) (\s :: TrialComponentParameterValue
s@TrialComponentParameterValue' {} Maybe Double
a -> TrialComponentParameterValue
s {$sel:numberValue:TrialComponentParameterValue' :: Maybe Double
numberValue = Maybe Double
a} :: TrialComponentParameterValue)

-- | The string value of a categorical hyperparameter. If you specify a value
-- for this parameter, you can\'t specify the @NumberValue@ parameter.
trialComponentParameterValue_stringValue :: Lens.Lens' TrialComponentParameterValue (Prelude.Maybe Prelude.Text)
trialComponentParameterValue_stringValue :: (Maybe Text -> f (Maybe Text))
-> TrialComponentParameterValue -> f TrialComponentParameterValue
trialComponentParameterValue_stringValue = (TrialComponentParameterValue -> Maybe Text)
-> (TrialComponentParameterValue
    -> Maybe Text -> TrialComponentParameterValue)
-> Lens
     TrialComponentParameterValue
     TrialComponentParameterValue
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TrialComponentParameterValue' {Maybe Text
stringValue :: Maybe Text
$sel:stringValue:TrialComponentParameterValue' :: TrialComponentParameterValue -> Maybe Text
stringValue} -> Maybe Text
stringValue) (\s :: TrialComponentParameterValue
s@TrialComponentParameterValue' {} Maybe Text
a -> TrialComponentParameterValue
s {$sel:stringValue:TrialComponentParameterValue' :: Maybe Text
stringValue = Maybe Text
a} :: TrialComponentParameterValue)

instance Core.FromJSON TrialComponentParameterValue where
  parseJSON :: Value -> Parser TrialComponentParameterValue
parseJSON =
    String
-> (Object -> Parser TrialComponentParameterValue)
-> Value
-> Parser TrialComponentParameterValue
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"TrialComponentParameterValue"
      ( \Object
x ->
          Maybe Double -> Maybe Text -> TrialComponentParameterValue
TrialComponentParameterValue'
            (Maybe Double -> Maybe Text -> TrialComponentParameterValue)
-> Parser (Maybe Double)
-> Parser (Maybe Text -> TrialComponentParameterValue)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"NumberValue")
            Parser (Maybe Text -> TrialComponentParameterValue)
-> Parser (Maybe Text) -> Parser TrialComponentParameterValue
forall (f :: * -> *) a b. Applicative f => 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
"StringValue")
      )

instance
  Prelude.Hashable
    TrialComponentParameterValue

instance Prelude.NFData TrialComponentParameterValue

instance Core.ToJSON TrialComponentParameterValue where
  toJSON :: TrialComponentParameterValue -> Value
toJSON TrialComponentParameterValue' {Maybe Double
Maybe Text
stringValue :: Maybe Text
numberValue :: Maybe Double
$sel:stringValue:TrialComponentParameterValue' :: TrialComponentParameterValue -> Maybe Text
$sel:numberValue:TrialComponentParameterValue' :: TrialComponentParameterValue -> Maybe Double
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"NumberValue" Text -> Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Double -> Pair) -> Maybe Double -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Double
numberValue,
            (Text
"StringValue" 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
stringValue
          ]
      )