{-# 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.Personalize.Types.HPOObjective
-- 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.Personalize.Types.HPOObjective 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 metric to optimize during hyperparameter optimization (HPO).
--
-- Amazon Personalize doesn\'t support configuring the @hpoObjective@ at
-- this time.
--
-- /See:/ 'newHPOObjective' smart constructor.
data HPOObjective = HPOObjective'
  { -- | The name of the metric.
    HPOObjective -> Maybe Text
metricName :: Prelude.Maybe Prelude.Text,
    -- | A regular expression for finding the metric in the training job logs.
    HPOObjective -> Maybe Text
metricRegex :: Prelude.Maybe Prelude.Text,
    -- | The type of the metric. Valid values are @Maximize@ and @Minimize@.
    HPOObjective -> Maybe Text
type' :: Prelude.Maybe Prelude.Text
  }
  deriving (HPOObjective -> HPOObjective -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HPOObjective -> HPOObjective -> Bool
$c/= :: HPOObjective -> HPOObjective -> Bool
== :: HPOObjective -> HPOObjective -> Bool
$c== :: HPOObjective -> HPOObjective -> Bool
Prelude.Eq, ReadPrec [HPOObjective]
ReadPrec HPOObjective
Int -> ReadS HPOObjective
ReadS [HPOObjective]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [HPOObjective]
$creadListPrec :: ReadPrec [HPOObjective]
readPrec :: ReadPrec HPOObjective
$creadPrec :: ReadPrec HPOObjective
readList :: ReadS [HPOObjective]
$creadList :: ReadS [HPOObjective]
readsPrec :: Int -> ReadS HPOObjective
$creadsPrec :: Int -> ReadS HPOObjective
Prelude.Read, Int -> HPOObjective -> ShowS
[HPOObjective] -> ShowS
HPOObjective -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HPOObjective] -> ShowS
$cshowList :: [HPOObjective] -> ShowS
show :: HPOObjective -> String
$cshow :: HPOObjective -> String
showsPrec :: Int -> HPOObjective -> ShowS
$cshowsPrec :: Int -> HPOObjective -> ShowS
Prelude.Show, forall x. Rep HPOObjective x -> HPOObjective
forall x. HPOObjective -> Rep HPOObjective x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep HPOObjective x -> HPOObjective
$cfrom :: forall x. HPOObjective -> Rep HPOObjective x
Prelude.Generic)

-- |
-- Create a value of 'HPOObjective' 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:
--
-- 'metricName', 'hPOObjective_metricName' - The name of the metric.
--
-- 'metricRegex', 'hPOObjective_metricRegex' - A regular expression for finding the metric in the training job logs.
--
-- 'type'', 'hPOObjective_type' - The type of the metric. Valid values are @Maximize@ and @Minimize@.
newHPOObjective ::
  HPOObjective
newHPOObjective :: HPOObjective
newHPOObjective =
  HPOObjective'
    { $sel:metricName:HPOObjective' :: Maybe Text
metricName = forall a. Maybe a
Prelude.Nothing,
      $sel:metricRegex:HPOObjective' :: Maybe Text
metricRegex = forall a. Maybe a
Prelude.Nothing,
      $sel:type':HPOObjective' :: Maybe Text
type' = forall a. Maybe a
Prelude.Nothing
    }

-- | The name of the metric.
hPOObjective_metricName :: Lens.Lens' HPOObjective (Prelude.Maybe Prelude.Text)
hPOObjective_metricName :: Lens' HPOObjective (Maybe Text)
hPOObjective_metricName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HPOObjective' {Maybe Text
metricName :: Maybe Text
$sel:metricName:HPOObjective' :: HPOObjective -> Maybe Text
metricName} -> Maybe Text
metricName) (\s :: HPOObjective
s@HPOObjective' {} Maybe Text
a -> HPOObjective
s {$sel:metricName:HPOObjective' :: Maybe Text
metricName = Maybe Text
a} :: HPOObjective)

-- | A regular expression for finding the metric in the training job logs.
hPOObjective_metricRegex :: Lens.Lens' HPOObjective (Prelude.Maybe Prelude.Text)
hPOObjective_metricRegex :: Lens' HPOObjective (Maybe Text)
hPOObjective_metricRegex = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HPOObjective' {Maybe Text
metricRegex :: Maybe Text
$sel:metricRegex:HPOObjective' :: HPOObjective -> Maybe Text
metricRegex} -> Maybe Text
metricRegex) (\s :: HPOObjective
s@HPOObjective' {} Maybe Text
a -> HPOObjective
s {$sel:metricRegex:HPOObjective' :: Maybe Text
metricRegex = Maybe Text
a} :: HPOObjective)

-- | The type of the metric. Valid values are @Maximize@ and @Minimize@.
hPOObjective_type :: Lens.Lens' HPOObjective (Prelude.Maybe Prelude.Text)
hPOObjective_type :: Lens' HPOObjective (Maybe Text)
hPOObjective_type = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HPOObjective' {Maybe Text
type' :: Maybe Text
$sel:type':HPOObjective' :: HPOObjective -> Maybe Text
type'} -> Maybe Text
type') (\s :: HPOObjective
s@HPOObjective' {} Maybe Text
a -> HPOObjective
s {$sel:type':HPOObjective' :: Maybe Text
type' = Maybe Text
a} :: HPOObjective)

instance Data.FromJSON HPOObjective where
  parseJSON :: Value -> Parser HPOObjective
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"HPOObjective"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> Maybe Text -> HPOObjective
HPOObjective'
            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
"metricName")
            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
"metricRegex")
            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
"type")
      )

instance Prelude.Hashable HPOObjective where
  hashWithSalt :: Int -> HPOObjective -> Int
hashWithSalt Int
_salt HPOObjective' {Maybe Text
type' :: Maybe Text
metricRegex :: Maybe Text
metricName :: Maybe Text
$sel:type':HPOObjective' :: HPOObjective -> Maybe Text
$sel:metricRegex:HPOObjective' :: HPOObjective -> Maybe Text
$sel:metricName:HPOObjective' :: HPOObjective -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
metricName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
metricRegex
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
type'

instance Prelude.NFData HPOObjective where
  rnf :: HPOObjective -> ()
rnf HPOObjective' {Maybe Text
type' :: Maybe Text
metricRegex :: Maybe Text
metricName :: Maybe Text
$sel:type':HPOObjective' :: HPOObjective -> Maybe Text
$sel:metricRegex:HPOObjective' :: HPOObjective -> Maybe Text
$sel:metricName:HPOObjective' :: HPOObjective -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
metricName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
metricRegex
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
type'

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