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

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

-- | Custom prioritization settings for use by a game session queue when
-- placing new game sessions with available game servers. When defined,
-- this configuration replaces the default FleetIQ prioritization process,
-- which is as follows:
--
-- -   If player latency data is included in a game session request,
--     destinations and locations are prioritized first based on lowest
--     average latency (1), then on lowest hosting cost (2), then on
--     destination list order (3), and finally on location (alphabetical)
--     (4). This approach ensures that the queue\'s top priority is to
--     place game sessions where average player latency is lowest, and--if
--     latency is the same--where the hosting cost is less, etc.
--
-- -   If player latency data is not included, destinations and locations
--     are prioritized first on destination list order (1), and then on
--     location (alphabetical) (2). This approach ensures that the queue\'s
--     top priority is to place game sessions on the first destination
--     fleet listed. If that fleet has multiple locations, the game session
--     is placed on the first location (when listed alphabetically).
--
-- Changing the priority order will affect how game sessions are placed.
--
-- Priority configurations are part of a GameSessionQueue.
--
-- /See:/ 'newPriorityConfiguration' smart constructor.
data PriorityConfiguration = PriorityConfiguration'
  { -- | The recommended sequence to use when prioritizing where to place new
    -- game sessions. Each type can only be listed once.
    --
    -- -   @LATENCY@ -- FleetIQ prioritizes locations where the average player
    --     latency (provided in each game session request) is lowest.
    --
    -- -   @COST@ -- FleetIQ prioritizes destinations with the lowest current
    --     hosting costs. Cost is evaluated based on the location, instance
    --     type, and fleet type (Spot or On-Demand) for each destination in the
    --     queue.
    --
    -- -   @DESTINATION@ -- FleetIQ prioritizes based on the order that
    --     destinations are listed in the queue configuration.
    --
    -- -   @LOCATION@ -- FleetIQ prioritizes based on the provided order of
    --     locations, as defined in @LocationOrder@.
    PriorityConfiguration -> Maybe (NonEmpty PriorityType)
priorityOrder :: Prelude.Maybe (Prelude.NonEmpty PriorityType),
    -- | The prioritization order to use for fleet locations, when the
    -- @PriorityOrder@ property includes @LOCATION@. Locations are identified
    -- by AWS Region codes such as @us-west-2@. Each location can only be
    -- listed once.
    PriorityConfiguration -> Maybe (NonEmpty Text)
locationOrder :: Prelude.Maybe (Prelude.NonEmpty Prelude.Text)
  }
  deriving (PriorityConfiguration -> PriorityConfiguration -> Bool
(PriorityConfiguration -> PriorityConfiguration -> Bool)
-> (PriorityConfiguration -> PriorityConfiguration -> Bool)
-> Eq PriorityConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PriorityConfiguration -> PriorityConfiguration -> Bool
$c/= :: PriorityConfiguration -> PriorityConfiguration -> Bool
== :: PriorityConfiguration -> PriorityConfiguration -> Bool
$c== :: PriorityConfiguration -> PriorityConfiguration -> Bool
Prelude.Eq, ReadPrec [PriorityConfiguration]
ReadPrec PriorityConfiguration
Int -> ReadS PriorityConfiguration
ReadS [PriorityConfiguration]
(Int -> ReadS PriorityConfiguration)
-> ReadS [PriorityConfiguration]
-> ReadPrec PriorityConfiguration
-> ReadPrec [PriorityConfiguration]
-> Read PriorityConfiguration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PriorityConfiguration]
$creadListPrec :: ReadPrec [PriorityConfiguration]
readPrec :: ReadPrec PriorityConfiguration
$creadPrec :: ReadPrec PriorityConfiguration
readList :: ReadS [PriorityConfiguration]
$creadList :: ReadS [PriorityConfiguration]
readsPrec :: Int -> ReadS PriorityConfiguration
$creadsPrec :: Int -> ReadS PriorityConfiguration
Prelude.Read, Int -> PriorityConfiguration -> ShowS
[PriorityConfiguration] -> ShowS
PriorityConfiguration -> String
(Int -> PriorityConfiguration -> ShowS)
-> (PriorityConfiguration -> String)
-> ([PriorityConfiguration] -> ShowS)
-> Show PriorityConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PriorityConfiguration] -> ShowS
$cshowList :: [PriorityConfiguration] -> ShowS
show :: PriorityConfiguration -> String
$cshow :: PriorityConfiguration -> String
showsPrec :: Int -> PriorityConfiguration -> ShowS
$cshowsPrec :: Int -> PriorityConfiguration -> ShowS
Prelude.Show, (forall x. PriorityConfiguration -> Rep PriorityConfiguration x)
-> (forall x. Rep PriorityConfiguration x -> PriorityConfiguration)
-> Generic PriorityConfiguration
forall x. Rep PriorityConfiguration x -> PriorityConfiguration
forall x. PriorityConfiguration -> Rep PriorityConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PriorityConfiguration x -> PriorityConfiguration
$cfrom :: forall x. PriorityConfiguration -> Rep PriorityConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'PriorityConfiguration' 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:
--
-- 'priorityOrder', 'priorityConfiguration_priorityOrder' - The recommended sequence to use when prioritizing where to place new
-- game sessions. Each type can only be listed once.
--
-- -   @LATENCY@ -- FleetIQ prioritizes locations where the average player
--     latency (provided in each game session request) is lowest.
--
-- -   @COST@ -- FleetIQ prioritizes destinations with the lowest current
--     hosting costs. Cost is evaluated based on the location, instance
--     type, and fleet type (Spot or On-Demand) for each destination in the
--     queue.
--
-- -   @DESTINATION@ -- FleetIQ prioritizes based on the order that
--     destinations are listed in the queue configuration.
--
-- -   @LOCATION@ -- FleetIQ prioritizes based on the provided order of
--     locations, as defined in @LocationOrder@.
--
-- 'locationOrder', 'priorityConfiguration_locationOrder' - The prioritization order to use for fleet locations, when the
-- @PriorityOrder@ property includes @LOCATION@. Locations are identified
-- by AWS Region codes such as @us-west-2@. Each location can only be
-- listed once.
newPriorityConfiguration ::
  PriorityConfiguration
newPriorityConfiguration :: PriorityConfiguration
newPriorityConfiguration =
  PriorityConfiguration' :: Maybe (NonEmpty PriorityType)
-> Maybe (NonEmpty Text) -> PriorityConfiguration
PriorityConfiguration'
    { $sel:priorityOrder:PriorityConfiguration' :: Maybe (NonEmpty PriorityType)
priorityOrder =
        Maybe (NonEmpty PriorityType)
forall a. Maybe a
Prelude.Nothing,
      $sel:locationOrder:PriorityConfiguration' :: Maybe (NonEmpty Text)
locationOrder = Maybe (NonEmpty Text)
forall a. Maybe a
Prelude.Nothing
    }

-- | The recommended sequence to use when prioritizing where to place new
-- game sessions. Each type can only be listed once.
--
-- -   @LATENCY@ -- FleetIQ prioritizes locations where the average player
--     latency (provided in each game session request) is lowest.
--
-- -   @COST@ -- FleetIQ prioritizes destinations with the lowest current
--     hosting costs. Cost is evaluated based on the location, instance
--     type, and fleet type (Spot or On-Demand) for each destination in the
--     queue.
--
-- -   @DESTINATION@ -- FleetIQ prioritizes based on the order that
--     destinations are listed in the queue configuration.
--
-- -   @LOCATION@ -- FleetIQ prioritizes based on the provided order of
--     locations, as defined in @LocationOrder@.
priorityConfiguration_priorityOrder :: Lens.Lens' PriorityConfiguration (Prelude.Maybe (Prelude.NonEmpty PriorityType))
priorityConfiguration_priorityOrder :: (Maybe (NonEmpty PriorityType)
 -> f (Maybe (NonEmpty PriorityType)))
-> PriorityConfiguration -> f PriorityConfiguration
priorityConfiguration_priorityOrder = (PriorityConfiguration -> Maybe (NonEmpty PriorityType))
-> (PriorityConfiguration
    -> Maybe (NonEmpty PriorityType) -> PriorityConfiguration)
-> Lens
     PriorityConfiguration
     PriorityConfiguration
     (Maybe (NonEmpty PriorityType))
     (Maybe (NonEmpty PriorityType))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PriorityConfiguration' {Maybe (NonEmpty PriorityType)
priorityOrder :: Maybe (NonEmpty PriorityType)
$sel:priorityOrder:PriorityConfiguration' :: PriorityConfiguration -> Maybe (NonEmpty PriorityType)
priorityOrder} -> Maybe (NonEmpty PriorityType)
priorityOrder) (\s :: PriorityConfiguration
s@PriorityConfiguration' {} Maybe (NonEmpty PriorityType)
a -> PriorityConfiguration
s {$sel:priorityOrder:PriorityConfiguration' :: Maybe (NonEmpty PriorityType)
priorityOrder = Maybe (NonEmpty PriorityType)
a} :: PriorityConfiguration) ((Maybe (NonEmpty PriorityType)
  -> f (Maybe (NonEmpty PriorityType)))
 -> PriorityConfiguration -> f PriorityConfiguration)
-> ((Maybe (NonEmpty PriorityType)
     -> f (Maybe (NonEmpty PriorityType)))
    -> Maybe (NonEmpty PriorityType)
    -> f (Maybe (NonEmpty PriorityType)))
-> (Maybe (NonEmpty PriorityType)
    -> f (Maybe (NonEmpty PriorityType)))
-> PriorityConfiguration
-> f PriorityConfiguration
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty PriorityType)
  (NonEmpty PriorityType)
  (NonEmpty PriorityType)
  (NonEmpty PriorityType)
-> Iso
     (Maybe (NonEmpty PriorityType))
     (Maybe (NonEmpty PriorityType))
     (Maybe (NonEmpty PriorityType))
     (Maybe (NonEmpty PriorityType))
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  (NonEmpty PriorityType)
  (NonEmpty PriorityType)
  (NonEmpty PriorityType)
  (NonEmpty PriorityType)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The prioritization order to use for fleet locations, when the
-- @PriorityOrder@ property includes @LOCATION@. Locations are identified
-- by AWS Region codes such as @us-west-2@. Each location can only be
-- listed once.
priorityConfiguration_locationOrder :: Lens.Lens' PriorityConfiguration (Prelude.Maybe (Prelude.NonEmpty Prelude.Text))
priorityConfiguration_locationOrder :: (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> PriorityConfiguration -> f PriorityConfiguration
priorityConfiguration_locationOrder = (PriorityConfiguration -> Maybe (NonEmpty Text))
-> (PriorityConfiguration
    -> Maybe (NonEmpty Text) -> PriorityConfiguration)
-> Lens
     PriorityConfiguration
     PriorityConfiguration
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PriorityConfiguration' {Maybe (NonEmpty Text)
locationOrder :: Maybe (NonEmpty Text)
$sel:locationOrder:PriorityConfiguration' :: PriorityConfiguration -> Maybe (NonEmpty Text)
locationOrder} -> Maybe (NonEmpty Text)
locationOrder) (\s :: PriorityConfiguration
s@PriorityConfiguration' {} Maybe (NonEmpty Text)
a -> PriorityConfiguration
s {$sel:locationOrder:PriorityConfiguration' :: Maybe (NonEmpty Text)
locationOrder = Maybe (NonEmpty Text)
a} :: PriorityConfiguration) ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
 -> PriorityConfiguration -> f PriorityConfiguration)
-> ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
    -> Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> PriorityConfiguration
-> f PriorityConfiguration
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty Text) (NonEmpty Text) (NonEmpty Text) (NonEmpty Text)
-> Iso
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  (NonEmpty Text) (NonEmpty Text) (NonEmpty Text) (NonEmpty Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON PriorityConfiguration where
  parseJSON :: Value -> Parser PriorityConfiguration
parseJSON =
    String
-> (Object -> Parser PriorityConfiguration)
-> Value
-> Parser PriorityConfiguration
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"PriorityConfiguration"
      ( \Object
x ->
          Maybe (NonEmpty PriorityType)
-> Maybe (NonEmpty Text) -> PriorityConfiguration
PriorityConfiguration'
            (Maybe (NonEmpty PriorityType)
 -> Maybe (NonEmpty Text) -> PriorityConfiguration)
-> Parser (Maybe (NonEmpty PriorityType))
-> Parser (Maybe (NonEmpty Text) -> PriorityConfiguration)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (NonEmpty PriorityType))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"PriorityOrder")
            Parser (Maybe (NonEmpty Text) -> PriorityConfiguration)
-> Parser (Maybe (NonEmpty Text)) -> Parser PriorityConfiguration
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (NonEmpty Text))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"LocationOrder")
      )

instance Prelude.Hashable PriorityConfiguration

instance Prelude.NFData PriorityConfiguration

instance Core.ToJSON PriorityConfiguration where
  toJSON :: PriorityConfiguration -> Value
toJSON PriorityConfiguration' {Maybe (NonEmpty Text)
Maybe (NonEmpty PriorityType)
locationOrder :: Maybe (NonEmpty Text)
priorityOrder :: Maybe (NonEmpty PriorityType)
$sel:locationOrder:PriorityConfiguration' :: PriorityConfiguration -> Maybe (NonEmpty Text)
$sel:priorityOrder:PriorityConfiguration' :: PriorityConfiguration -> Maybe (NonEmpty PriorityType)
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"PriorityOrder" Text -> NonEmpty PriorityType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (NonEmpty PriorityType -> Pair)
-> Maybe (NonEmpty PriorityType) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty PriorityType)
priorityOrder,
            (Text
"LocationOrder" Text -> NonEmpty Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (NonEmpty Text -> Pair) -> Maybe (NonEmpty Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty Text)
locationOrder
          ]
      )