{-# 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.GameLift.Types.TargetConfiguration
-- 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.GameLift.Types.TargetConfiguration 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

-- | Settings for a target-based scaling policy. A target-based policy tracks
-- a particular fleet metric specifies a target value for the metric. As
-- player usage changes, the policy triggers Amazon GameLift to adjust
-- capacity so that the metric returns to the target value. The target
-- configuration specifies settings as needed for the target based policy,
-- including the target value.
--
-- /See:/ 'newTargetConfiguration' smart constructor.
data TargetConfiguration = TargetConfiguration'
  { -- | Desired value to use with a target-based scaling policy. The value must
    -- be relevant for whatever metric the scaling policy is using. For
    -- example, in a policy using the metric PercentAvailableGameSessions, the
    -- target value should be the preferred size of the fleet\'s buffer (the
    -- percent of capacity that should be idle and ready for new game
    -- sessions).
    TargetConfiguration -> Double
targetValue :: Prelude.Double
  }
  deriving (TargetConfiguration -> TargetConfiguration -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TargetConfiguration -> TargetConfiguration -> Bool
$c/= :: TargetConfiguration -> TargetConfiguration -> Bool
== :: TargetConfiguration -> TargetConfiguration -> Bool
$c== :: TargetConfiguration -> TargetConfiguration -> Bool
Prelude.Eq, ReadPrec [TargetConfiguration]
ReadPrec TargetConfiguration
Int -> ReadS TargetConfiguration
ReadS [TargetConfiguration]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TargetConfiguration]
$creadListPrec :: ReadPrec [TargetConfiguration]
readPrec :: ReadPrec TargetConfiguration
$creadPrec :: ReadPrec TargetConfiguration
readList :: ReadS [TargetConfiguration]
$creadList :: ReadS [TargetConfiguration]
readsPrec :: Int -> ReadS TargetConfiguration
$creadsPrec :: Int -> ReadS TargetConfiguration
Prelude.Read, Int -> TargetConfiguration -> ShowS
[TargetConfiguration] -> ShowS
TargetConfiguration -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TargetConfiguration] -> ShowS
$cshowList :: [TargetConfiguration] -> ShowS
show :: TargetConfiguration -> String
$cshow :: TargetConfiguration -> String
showsPrec :: Int -> TargetConfiguration -> ShowS
$cshowsPrec :: Int -> TargetConfiguration -> ShowS
Prelude.Show, forall x. Rep TargetConfiguration x -> TargetConfiguration
forall x. TargetConfiguration -> Rep TargetConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TargetConfiguration x -> TargetConfiguration
$cfrom :: forall x. TargetConfiguration -> Rep TargetConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'TargetConfiguration' 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:
--
-- 'targetValue', 'targetConfiguration_targetValue' - Desired value to use with a target-based scaling policy. The value must
-- be relevant for whatever metric the scaling policy is using. For
-- example, in a policy using the metric PercentAvailableGameSessions, the
-- target value should be the preferred size of the fleet\'s buffer (the
-- percent of capacity that should be idle and ready for new game
-- sessions).
newTargetConfiguration ::
  -- | 'targetValue'
  Prelude.Double ->
  TargetConfiguration
newTargetConfiguration :: Double -> TargetConfiguration
newTargetConfiguration Double
pTargetValue_ =
  TargetConfiguration' {$sel:targetValue:TargetConfiguration' :: Double
targetValue = Double
pTargetValue_}

-- | Desired value to use with a target-based scaling policy. The value must
-- be relevant for whatever metric the scaling policy is using. For
-- example, in a policy using the metric PercentAvailableGameSessions, the
-- target value should be the preferred size of the fleet\'s buffer (the
-- percent of capacity that should be idle and ready for new game
-- sessions).
targetConfiguration_targetValue :: Lens.Lens' TargetConfiguration Prelude.Double
targetConfiguration_targetValue :: Lens' TargetConfiguration Double
targetConfiguration_targetValue = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TargetConfiguration' {Double
targetValue :: Double
$sel:targetValue:TargetConfiguration' :: TargetConfiguration -> Double
targetValue} -> Double
targetValue) (\s :: TargetConfiguration
s@TargetConfiguration' {} Double
a -> TargetConfiguration
s {$sel:targetValue:TargetConfiguration' :: Double
targetValue = Double
a} :: TargetConfiguration)

instance Data.FromJSON TargetConfiguration where
  parseJSON :: Value -> Parser TargetConfiguration
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"TargetConfiguration"
      ( \Object
x ->
          Double -> TargetConfiguration
TargetConfiguration'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"TargetValue")
      )

instance Prelude.Hashable TargetConfiguration where
  hashWithSalt :: Int -> TargetConfiguration -> Int
hashWithSalt Int
_salt TargetConfiguration' {Double
targetValue :: Double
$sel:targetValue:TargetConfiguration' :: TargetConfiguration -> Double
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Double
targetValue

instance Prelude.NFData TargetConfiguration where
  rnf :: TargetConfiguration -> ()
rnf TargetConfiguration' {Double
targetValue :: Double
$sel:targetValue:TargetConfiguration' :: TargetConfiguration -> Double
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Double
targetValue

instance Data.ToJSON TargetConfiguration where
  toJSON :: TargetConfiguration -> Value
toJSON TargetConfiguration' {Double
targetValue :: Double
$sel:targetValue:TargetConfiguration' :: TargetConfiguration -> Double
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [forall a. a -> Maybe a
Prelude.Just (Key
"TargetValue" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Double
targetValue)]
      )