{-# 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.GameServerGroupAutoScalingPolicy
-- 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.GameServerGroupAutoScalingPolicy where

import qualified Amazonka.Core as Core
import Amazonka.GameLift.Types.TargetTrackingConfiguration
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | __This data type is used with the GameLift FleetIQ and game server
-- groups.__
--
-- Configuration settings for intelligent automatic scaling that uses
-- target tracking. These settings are used to add an Auto Scaling policy
-- when creating the corresponding Auto Scaling group with
-- CreateGameServerGroup. After the Auto Scaling group is created, all
-- updates to Auto Scaling policies, including changing this policy and
-- adding or removing other policies, is done directly on the Auto Scaling
-- group.
--
-- /See:/ 'newGameServerGroupAutoScalingPolicy' smart constructor.
data GameServerGroupAutoScalingPolicy = GameServerGroupAutoScalingPolicy'
  { -- | Length of time, in seconds, it takes for a new instance to start new
    -- game server processes and register with GameLift FleetIQ. Specifying a
    -- warm-up time can be useful, particularly with game servers that take a
    -- long time to start up, because it avoids prematurely starting new
    -- instances.
    GameServerGroupAutoScalingPolicy -> Maybe Natural
estimatedInstanceWarmup :: Prelude.Maybe Prelude.Natural,
    -- | Settings for a target-based scaling policy applied to Auto Scaling
    -- group. These settings are used to create a target-based policy that
    -- tracks the GameLift FleetIQ metric @\"PercentUtilizedGameServers\"@ and
    -- specifies a target value for the metric. As player usage changes, the
    -- policy triggers to adjust the game server group capacity so that the
    -- metric returns to the target value.
    GameServerGroupAutoScalingPolicy -> TargetTrackingConfiguration
targetTrackingConfiguration :: TargetTrackingConfiguration
  }
  deriving (GameServerGroupAutoScalingPolicy
-> GameServerGroupAutoScalingPolicy -> Bool
(GameServerGroupAutoScalingPolicy
 -> GameServerGroupAutoScalingPolicy -> Bool)
-> (GameServerGroupAutoScalingPolicy
    -> GameServerGroupAutoScalingPolicy -> Bool)
-> Eq GameServerGroupAutoScalingPolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GameServerGroupAutoScalingPolicy
-> GameServerGroupAutoScalingPolicy -> Bool
$c/= :: GameServerGroupAutoScalingPolicy
-> GameServerGroupAutoScalingPolicy -> Bool
== :: GameServerGroupAutoScalingPolicy
-> GameServerGroupAutoScalingPolicy -> Bool
$c== :: GameServerGroupAutoScalingPolicy
-> GameServerGroupAutoScalingPolicy -> Bool
Prelude.Eq, ReadPrec [GameServerGroupAutoScalingPolicy]
ReadPrec GameServerGroupAutoScalingPolicy
Int -> ReadS GameServerGroupAutoScalingPolicy
ReadS [GameServerGroupAutoScalingPolicy]
(Int -> ReadS GameServerGroupAutoScalingPolicy)
-> ReadS [GameServerGroupAutoScalingPolicy]
-> ReadPrec GameServerGroupAutoScalingPolicy
-> ReadPrec [GameServerGroupAutoScalingPolicy]
-> Read GameServerGroupAutoScalingPolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GameServerGroupAutoScalingPolicy]
$creadListPrec :: ReadPrec [GameServerGroupAutoScalingPolicy]
readPrec :: ReadPrec GameServerGroupAutoScalingPolicy
$creadPrec :: ReadPrec GameServerGroupAutoScalingPolicy
readList :: ReadS [GameServerGroupAutoScalingPolicy]
$creadList :: ReadS [GameServerGroupAutoScalingPolicy]
readsPrec :: Int -> ReadS GameServerGroupAutoScalingPolicy
$creadsPrec :: Int -> ReadS GameServerGroupAutoScalingPolicy
Prelude.Read, Int -> GameServerGroupAutoScalingPolicy -> ShowS
[GameServerGroupAutoScalingPolicy] -> ShowS
GameServerGroupAutoScalingPolicy -> String
(Int -> GameServerGroupAutoScalingPolicy -> ShowS)
-> (GameServerGroupAutoScalingPolicy -> String)
-> ([GameServerGroupAutoScalingPolicy] -> ShowS)
-> Show GameServerGroupAutoScalingPolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GameServerGroupAutoScalingPolicy] -> ShowS
$cshowList :: [GameServerGroupAutoScalingPolicy] -> ShowS
show :: GameServerGroupAutoScalingPolicy -> String
$cshow :: GameServerGroupAutoScalingPolicy -> String
showsPrec :: Int -> GameServerGroupAutoScalingPolicy -> ShowS
$cshowsPrec :: Int -> GameServerGroupAutoScalingPolicy -> ShowS
Prelude.Show, (forall x.
 GameServerGroupAutoScalingPolicy
 -> Rep GameServerGroupAutoScalingPolicy x)
-> (forall x.
    Rep GameServerGroupAutoScalingPolicy x
    -> GameServerGroupAutoScalingPolicy)
-> Generic GameServerGroupAutoScalingPolicy
forall x.
Rep GameServerGroupAutoScalingPolicy x
-> GameServerGroupAutoScalingPolicy
forall x.
GameServerGroupAutoScalingPolicy
-> Rep GameServerGroupAutoScalingPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GameServerGroupAutoScalingPolicy x
-> GameServerGroupAutoScalingPolicy
$cfrom :: forall x.
GameServerGroupAutoScalingPolicy
-> Rep GameServerGroupAutoScalingPolicy x
Prelude.Generic)

-- |
-- Create a value of 'GameServerGroupAutoScalingPolicy' 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:
--
-- 'estimatedInstanceWarmup', 'gameServerGroupAutoScalingPolicy_estimatedInstanceWarmup' - Length of time, in seconds, it takes for a new instance to start new
-- game server processes and register with GameLift FleetIQ. Specifying a
-- warm-up time can be useful, particularly with game servers that take a
-- long time to start up, because it avoids prematurely starting new
-- instances.
--
-- 'targetTrackingConfiguration', 'gameServerGroupAutoScalingPolicy_targetTrackingConfiguration' - Settings for a target-based scaling policy applied to Auto Scaling
-- group. These settings are used to create a target-based policy that
-- tracks the GameLift FleetIQ metric @\"PercentUtilizedGameServers\"@ and
-- specifies a target value for the metric. As player usage changes, the
-- policy triggers to adjust the game server group capacity so that the
-- metric returns to the target value.
newGameServerGroupAutoScalingPolicy ::
  -- | 'targetTrackingConfiguration'
  TargetTrackingConfiguration ->
  GameServerGroupAutoScalingPolicy
newGameServerGroupAutoScalingPolicy :: TargetTrackingConfiguration -> GameServerGroupAutoScalingPolicy
newGameServerGroupAutoScalingPolicy
  TargetTrackingConfiguration
pTargetTrackingConfiguration_ =
    GameServerGroupAutoScalingPolicy' :: Maybe Natural
-> TargetTrackingConfiguration -> GameServerGroupAutoScalingPolicy
GameServerGroupAutoScalingPolicy'
      { $sel:estimatedInstanceWarmup:GameServerGroupAutoScalingPolicy' :: Maybe Natural
estimatedInstanceWarmup =
          Maybe Natural
forall a. Maybe a
Prelude.Nothing,
        $sel:targetTrackingConfiguration:GameServerGroupAutoScalingPolicy' :: TargetTrackingConfiguration
targetTrackingConfiguration =
          TargetTrackingConfiguration
pTargetTrackingConfiguration_
      }

-- | Length of time, in seconds, it takes for a new instance to start new
-- game server processes and register with GameLift FleetIQ. Specifying a
-- warm-up time can be useful, particularly with game servers that take a
-- long time to start up, because it avoids prematurely starting new
-- instances.
gameServerGroupAutoScalingPolicy_estimatedInstanceWarmup :: Lens.Lens' GameServerGroupAutoScalingPolicy (Prelude.Maybe Prelude.Natural)
gameServerGroupAutoScalingPolicy_estimatedInstanceWarmup :: (Maybe Natural -> f (Maybe Natural))
-> GameServerGroupAutoScalingPolicy
-> f GameServerGroupAutoScalingPolicy
gameServerGroupAutoScalingPolicy_estimatedInstanceWarmup = (GameServerGroupAutoScalingPolicy -> Maybe Natural)
-> (GameServerGroupAutoScalingPolicy
    -> Maybe Natural -> GameServerGroupAutoScalingPolicy)
-> Lens
     GameServerGroupAutoScalingPolicy
     GameServerGroupAutoScalingPolicy
     (Maybe Natural)
     (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GameServerGroupAutoScalingPolicy' {Maybe Natural
estimatedInstanceWarmup :: Maybe Natural
$sel:estimatedInstanceWarmup:GameServerGroupAutoScalingPolicy' :: GameServerGroupAutoScalingPolicy -> Maybe Natural
estimatedInstanceWarmup} -> Maybe Natural
estimatedInstanceWarmup) (\s :: GameServerGroupAutoScalingPolicy
s@GameServerGroupAutoScalingPolicy' {} Maybe Natural
a -> GameServerGroupAutoScalingPolicy
s {$sel:estimatedInstanceWarmup:GameServerGroupAutoScalingPolicy' :: Maybe Natural
estimatedInstanceWarmup = Maybe Natural
a} :: GameServerGroupAutoScalingPolicy)

-- | Settings for a target-based scaling policy applied to Auto Scaling
-- group. These settings are used to create a target-based policy that
-- tracks the GameLift FleetIQ metric @\"PercentUtilizedGameServers\"@ and
-- specifies a target value for the metric. As player usage changes, the
-- policy triggers to adjust the game server group capacity so that the
-- metric returns to the target value.
gameServerGroupAutoScalingPolicy_targetTrackingConfiguration :: Lens.Lens' GameServerGroupAutoScalingPolicy TargetTrackingConfiguration
gameServerGroupAutoScalingPolicy_targetTrackingConfiguration :: (TargetTrackingConfiguration -> f TargetTrackingConfiguration)
-> GameServerGroupAutoScalingPolicy
-> f GameServerGroupAutoScalingPolicy
gameServerGroupAutoScalingPolicy_targetTrackingConfiguration = (GameServerGroupAutoScalingPolicy -> TargetTrackingConfiguration)
-> (GameServerGroupAutoScalingPolicy
    -> TargetTrackingConfiguration -> GameServerGroupAutoScalingPolicy)
-> Lens
     GameServerGroupAutoScalingPolicy
     GameServerGroupAutoScalingPolicy
     TargetTrackingConfiguration
     TargetTrackingConfiguration
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GameServerGroupAutoScalingPolicy' {TargetTrackingConfiguration
targetTrackingConfiguration :: TargetTrackingConfiguration
$sel:targetTrackingConfiguration:GameServerGroupAutoScalingPolicy' :: GameServerGroupAutoScalingPolicy -> TargetTrackingConfiguration
targetTrackingConfiguration} -> TargetTrackingConfiguration
targetTrackingConfiguration) (\s :: GameServerGroupAutoScalingPolicy
s@GameServerGroupAutoScalingPolicy' {} TargetTrackingConfiguration
a -> GameServerGroupAutoScalingPolicy
s {$sel:targetTrackingConfiguration:GameServerGroupAutoScalingPolicy' :: TargetTrackingConfiguration
targetTrackingConfiguration = TargetTrackingConfiguration
a} :: GameServerGroupAutoScalingPolicy)

instance
  Prelude.Hashable
    GameServerGroupAutoScalingPolicy

instance
  Prelude.NFData
    GameServerGroupAutoScalingPolicy

instance Core.ToJSON GameServerGroupAutoScalingPolicy where
  toJSON :: GameServerGroupAutoScalingPolicy -> Value
toJSON GameServerGroupAutoScalingPolicy' {Maybe Natural
TargetTrackingConfiguration
targetTrackingConfiguration :: TargetTrackingConfiguration
estimatedInstanceWarmup :: Maybe Natural
$sel:targetTrackingConfiguration:GameServerGroupAutoScalingPolicy' :: GameServerGroupAutoScalingPolicy -> TargetTrackingConfiguration
$sel:estimatedInstanceWarmup:GameServerGroupAutoScalingPolicy' :: GameServerGroupAutoScalingPolicy -> Maybe Natural
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"EstimatedInstanceWarmup" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
estimatedInstanceWarmup,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              ( Text
"TargetTrackingConfiguration"
                  Text -> TargetTrackingConfiguration -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= TargetTrackingConfiguration
targetTrackingConfiguration
              )
          ]
      )