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

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

-- | Settings for a target-based scaling policy (see ScalingPolicy. 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.
--
-- __Related actions__
--
-- DescribeFleetCapacity | UpdateFleetCapacity | DescribeEC2InstanceLimits
-- | PutScalingPolicy | DescribeScalingPolicies | DeleteScalingPolicy |
-- StopFleetActions | StartFleetActions |
-- <https://docs.aws.amazon.com/gamelift/latest/developerguide/reference-awssdk.html#reference-awssdk-resources-fleets All APIs by task>
--
-- /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
(TargetConfiguration -> TargetConfiguration -> Bool)
-> (TargetConfiguration -> TargetConfiguration -> Bool)
-> Eq TargetConfiguration
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]
(Int -> ReadS TargetConfiguration)
-> ReadS [TargetConfiguration]
-> ReadPrec TargetConfiguration
-> ReadPrec [TargetConfiguration]
-> Read 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
(Int -> TargetConfiguration -> ShowS)
-> (TargetConfiguration -> String)
-> ([TargetConfiguration] -> ShowS)
-> Show TargetConfiguration
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. TargetConfiguration -> Rep TargetConfiguration x)
-> (forall x. Rep TargetConfiguration x -> TargetConfiguration)
-> Generic TargetConfiguration
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' :: Double -> TargetConfiguration
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 :: (Double -> f Double)
-> TargetConfiguration -> f TargetConfiguration
targetConfiguration_targetValue = (TargetConfiguration -> Double)
-> (TargetConfiguration -> Double -> TargetConfiguration)
-> Lens TargetConfiguration TargetConfiguration Double Double
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 Core.FromJSON TargetConfiguration where
  parseJSON :: Value -> Parser TargetConfiguration
parseJSON =
    String
-> (Object -> Parser TargetConfiguration)
-> Value
-> Parser TargetConfiguration
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"TargetConfiguration"
      ( \Object
x ->
          Double -> TargetConfiguration
TargetConfiguration'
            (Double -> TargetConfiguration)
-> Parser Double -> Parser TargetConfiguration
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Double
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"TargetValue")
      )

instance Prelude.Hashable TargetConfiguration

instance Prelude.NFData TargetConfiguration

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