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

import qualified Amazonka.Core as Core
import Amazonka.GameLift.Types.GameServerGroupInstanceType
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.__
--
-- An allowed instance type for a GameServerGroup. All game server groups
-- must have at least two instance types defined for it. GameLift FleetIQ
-- periodically evaluates each defined instance type for viability. It then
-- updates the Auto Scaling group with the list of viable instance types.
--
-- /See:/ 'newInstanceDefinition' smart constructor.
data InstanceDefinition = InstanceDefinition'
  { -- | Instance weighting that indicates how much this instance type
    -- contributes to the total capacity of a game server group. Instance
    -- weights are used by GameLift FleetIQ to calculate the instance type\'s
    -- cost per unit hour and better identify the most cost-effective options.
    -- For detailed information on weighting instance capacity, see
    -- <https://docs.aws.amazon.com/autoscaling/ec2/userguide/asg-instance-weighting.html Instance Weighting>
    -- in the /Amazon EC2 Auto Scaling User Guide/. Default value is \"1\".
    InstanceDefinition -> Maybe Text
weightedCapacity :: Prelude.Maybe Prelude.Text,
    -- | An EC2 instance type designation.
    InstanceDefinition -> GameServerGroupInstanceType
instanceType :: GameServerGroupInstanceType
  }
  deriving (InstanceDefinition -> InstanceDefinition -> Bool
(InstanceDefinition -> InstanceDefinition -> Bool)
-> (InstanceDefinition -> InstanceDefinition -> Bool)
-> Eq InstanceDefinition
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: InstanceDefinition -> InstanceDefinition -> Bool
$c/= :: InstanceDefinition -> InstanceDefinition -> Bool
== :: InstanceDefinition -> InstanceDefinition -> Bool
$c== :: InstanceDefinition -> InstanceDefinition -> Bool
Prelude.Eq, ReadPrec [InstanceDefinition]
ReadPrec InstanceDefinition
Int -> ReadS InstanceDefinition
ReadS [InstanceDefinition]
(Int -> ReadS InstanceDefinition)
-> ReadS [InstanceDefinition]
-> ReadPrec InstanceDefinition
-> ReadPrec [InstanceDefinition]
-> Read InstanceDefinition
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [InstanceDefinition]
$creadListPrec :: ReadPrec [InstanceDefinition]
readPrec :: ReadPrec InstanceDefinition
$creadPrec :: ReadPrec InstanceDefinition
readList :: ReadS [InstanceDefinition]
$creadList :: ReadS [InstanceDefinition]
readsPrec :: Int -> ReadS InstanceDefinition
$creadsPrec :: Int -> ReadS InstanceDefinition
Prelude.Read, Int -> InstanceDefinition -> ShowS
[InstanceDefinition] -> ShowS
InstanceDefinition -> String
(Int -> InstanceDefinition -> ShowS)
-> (InstanceDefinition -> String)
-> ([InstanceDefinition] -> ShowS)
-> Show InstanceDefinition
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InstanceDefinition] -> ShowS
$cshowList :: [InstanceDefinition] -> ShowS
show :: InstanceDefinition -> String
$cshow :: InstanceDefinition -> String
showsPrec :: Int -> InstanceDefinition -> ShowS
$cshowsPrec :: Int -> InstanceDefinition -> ShowS
Prelude.Show, (forall x. InstanceDefinition -> Rep InstanceDefinition x)
-> (forall x. Rep InstanceDefinition x -> InstanceDefinition)
-> Generic InstanceDefinition
forall x. Rep InstanceDefinition x -> InstanceDefinition
forall x. InstanceDefinition -> Rep InstanceDefinition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep InstanceDefinition x -> InstanceDefinition
$cfrom :: forall x. InstanceDefinition -> Rep InstanceDefinition x
Prelude.Generic)

-- |
-- Create a value of 'InstanceDefinition' 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:
--
-- 'weightedCapacity', 'instanceDefinition_weightedCapacity' - Instance weighting that indicates how much this instance type
-- contributes to the total capacity of a game server group. Instance
-- weights are used by GameLift FleetIQ to calculate the instance type\'s
-- cost per unit hour and better identify the most cost-effective options.
-- For detailed information on weighting instance capacity, see
-- <https://docs.aws.amazon.com/autoscaling/ec2/userguide/asg-instance-weighting.html Instance Weighting>
-- in the /Amazon EC2 Auto Scaling User Guide/. Default value is \"1\".
--
-- 'instanceType', 'instanceDefinition_instanceType' - An EC2 instance type designation.
newInstanceDefinition ::
  -- | 'instanceType'
  GameServerGroupInstanceType ->
  InstanceDefinition
newInstanceDefinition :: GameServerGroupInstanceType -> InstanceDefinition
newInstanceDefinition GameServerGroupInstanceType
pInstanceType_ =
  InstanceDefinition' :: Maybe Text -> GameServerGroupInstanceType -> InstanceDefinition
InstanceDefinition'
    { $sel:weightedCapacity:InstanceDefinition' :: Maybe Text
weightedCapacity =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:instanceType:InstanceDefinition' :: GameServerGroupInstanceType
instanceType = GameServerGroupInstanceType
pInstanceType_
    }

-- | Instance weighting that indicates how much this instance type
-- contributes to the total capacity of a game server group. Instance
-- weights are used by GameLift FleetIQ to calculate the instance type\'s
-- cost per unit hour and better identify the most cost-effective options.
-- For detailed information on weighting instance capacity, see
-- <https://docs.aws.amazon.com/autoscaling/ec2/userguide/asg-instance-weighting.html Instance Weighting>
-- in the /Amazon EC2 Auto Scaling User Guide/. Default value is \"1\".
instanceDefinition_weightedCapacity :: Lens.Lens' InstanceDefinition (Prelude.Maybe Prelude.Text)
instanceDefinition_weightedCapacity :: (Maybe Text -> f (Maybe Text))
-> InstanceDefinition -> f InstanceDefinition
instanceDefinition_weightedCapacity = (InstanceDefinition -> Maybe Text)
-> (InstanceDefinition -> Maybe Text -> InstanceDefinition)
-> Lens
     InstanceDefinition InstanceDefinition (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InstanceDefinition' {Maybe Text
weightedCapacity :: Maybe Text
$sel:weightedCapacity:InstanceDefinition' :: InstanceDefinition -> Maybe Text
weightedCapacity} -> Maybe Text
weightedCapacity) (\s :: InstanceDefinition
s@InstanceDefinition' {} Maybe Text
a -> InstanceDefinition
s {$sel:weightedCapacity:InstanceDefinition' :: Maybe Text
weightedCapacity = Maybe Text
a} :: InstanceDefinition)

-- | An EC2 instance type designation.
instanceDefinition_instanceType :: Lens.Lens' InstanceDefinition GameServerGroupInstanceType
instanceDefinition_instanceType :: (GameServerGroupInstanceType -> f GameServerGroupInstanceType)
-> InstanceDefinition -> f InstanceDefinition
instanceDefinition_instanceType = (InstanceDefinition -> GameServerGroupInstanceType)
-> (InstanceDefinition
    -> GameServerGroupInstanceType -> InstanceDefinition)
-> Lens
     InstanceDefinition
     InstanceDefinition
     GameServerGroupInstanceType
     GameServerGroupInstanceType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InstanceDefinition' {GameServerGroupInstanceType
instanceType :: GameServerGroupInstanceType
$sel:instanceType:InstanceDefinition' :: InstanceDefinition -> GameServerGroupInstanceType
instanceType} -> GameServerGroupInstanceType
instanceType) (\s :: InstanceDefinition
s@InstanceDefinition' {} GameServerGroupInstanceType
a -> InstanceDefinition
s {$sel:instanceType:InstanceDefinition' :: GameServerGroupInstanceType
instanceType = GameServerGroupInstanceType
a} :: InstanceDefinition)

instance Core.FromJSON InstanceDefinition where
  parseJSON :: Value -> Parser InstanceDefinition
parseJSON =
    String
-> (Object -> Parser InstanceDefinition)
-> Value
-> Parser InstanceDefinition
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"InstanceDefinition"
      ( \Object
x ->
          Maybe Text -> GameServerGroupInstanceType -> InstanceDefinition
InstanceDefinition'
            (Maybe Text -> GameServerGroupInstanceType -> InstanceDefinition)
-> Parser (Maybe Text)
-> Parser (GameServerGroupInstanceType -> InstanceDefinition)
forall (f :: * -> *) a b. Functor 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
"WeightedCapacity")
            Parser (GameServerGroupInstanceType -> InstanceDefinition)
-> Parser GameServerGroupInstanceType -> Parser InstanceDefinition
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser GameServerGroupInstanceType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"InstanceType")
      )

instance Prelude.Hashable InstanceDefinition

instance Prelude.NFData InstanceDefinition

instance Core.ToJSON InstanceDefinition where
  toJSON :: InstanceDefinition -> Value
toJSON InstanceDefinition' {Maybe Text
GameServerGroupInstanceType
instanceType :: GameServerGroupInstanceType
weightedCapacity :: Maybe Text
$sel:instanceType:InstanceDefinition' :: InstanceDefinition -> GameServerGroupInstanceType
$sel:weightedCapacity:InstanceDefinition' :: InstanceDefinition -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"WeightedCapacity" 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
weightedCapacity,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"InstanceType" Text -> GameServerGroupInstanceType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= GameServerGroupInstanceType
instanceType)
          ]
      )