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

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.GameLift.Types.PriorityType
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.
--
-- /See:/ 'newPriorityConfiguration' smart constructor.
data PriorityConfiguration = PriorityConfiguration'
  { -- | The prioritization order to use for fleet locations, when the
    -- @PriorityOrder@ property includes @LOCATION@. Locations are identified
    -- by Amazon Web Services 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),
    -- | 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)
  }
  deriving (PriorityConfiguration -> PriorityConfiguration -> Bool
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]
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
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. 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:
--
-- 'locationOrder', 'priorityConfiguration_locationOrder' - The prioritization order to use for fleet locations, when the
-- @PriorityOrder@ property includes @LOCATION@. Locations are identified
-- by Amazon Web Services Region codes such as @us-west-2@. Each location
-- can only be listed once.
--
-- '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@.
newPriorityConfiguration ::
  PriorityConfiguration
newPriorityConfiguration :: PriorityConfiguration
newPriorityConfiguration =
  PriorityConfiguration'
    { $sel:locationOrder:PriorityConfiguration' :: Maybe (NonEmpty Text)
locationOrder =
        forall a. Maybe a
Prelude.Nothing,
      $sel:priorityOrder:PriorityConfiguration' :: Maybe (NonEmpty PriorityType)
priorityOrder = forall a. Maybe a
Prelude.Nothing
    }

-- | The prioritization order to use for fleet locations, when the
-- @PriorityOrder@ property includes @LOCATION@. Locations are identified
-- by Amazon Web Services 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 :: Lens' PriorityConfiguration (Maybe (NonEmpty Text))
priorityConfiguration_locationOrder = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | 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 :: Lens' PriorityConfiguration (Maybe (NonEmpty PriorityType))
priorityConfiguration_priorityOrder = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable PriorityConfiguration where
  hashWithSalt :: Int -> PriorityConfiguration -> Int
hashWithSalt Int
_salt PriorityConfiguration' {Maybe (NonEmpty Text)
Maybe (NonEmpty PriorityType)
priorityOrder :: Maybe (NonEmpty PriorityType)
locationOrder :: Maybe (NonEmpty Text)
$sel:priorityOrder:PriorityConfiguration' :: PriorityConfiguration -> Maybe (NonEmpty PriorityType)
$sel:locationOrder:PriorityConfiguration' :: PriorityConfiguration -> Maybe (NonEmpty Text)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (NonEmpty Text)
locationOrder
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (NonEmpty PriorityType)
priorityOrder

instance Prelude.NFData PriorityConfiguration where
  rnf :: PriorityConfiguration -> ()
rnf PriorityConfiguration' {Maybe (NonEmpty Text)
Maybe (NonEmpty PriorityType)
priorityOrder :: Maybe (NonEmpty PriorityType)
locationOrder :: Maybe (NonEmpty Text)
$sel:priorityOrder:PriorityConfiguration' :: PriorityConfiguration -> Maybe (NonEmpty PriorityType)
$sel:locationOrder:PriorityConfiguration' :: PriorityConfiguration -> Maybe (NonEmpty Text)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (NonEmpty Text)
locationOrder
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (NonEmpty PriorityType)
priorityOrder

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