{-# 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.RoutingStrategy
-- 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.RoutingStrategy 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.RoutingStrategyType
import qualified Amazonka.Prelude as Prelude

-- | The routing configuration for a fleet alias.
--
-- __Related actions__
--
-- <https://docs.aws.amazon.com/gamelift/latest/developerguide/reference-awssdk.html#reference-awssdk-resources-fleets All APIs by task>
--
-- /See:/ 'newRoutingStrategy' smart constructor.
data RoutingStrategy = RoutingStrategy'
  { -- | A unique identifier for the fleet that the alias points to. This value
    -- is the fleet ID, not the fleet ARN.
    RoutingStrategy -> Maybe Text
fleetId :: Prelude.Maybe Prelude.Text,
    -- | The message text to be used with a terminal routing strategy.
    RoutingStrategy -> Maybe Text
message :: Prelude.Maybe Prelude.Text,
    -- | The type of routing strategy for the alias.
    --
    -- Possible routing types include the following:
    --
    -- -   __SIMPLE__ - The alias resolves to one specific fleet. Use this type
    --     when routing to active fleets.
    --
    -- -   __TERMINAL__ - The alias does not resolve to a fleet but instead can
    --     be used to display a message to the user. A terminal alias throws a
    --     TerminalRoutingStrategyException with the message embedded.
    RoutingStrategy -> Maybe RoutingStrategyType
type' :: Prelude.Maybe RoutingStrategyType
  }
  deriving (RoutingStrategy -> RoutingStrategy -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RoutingStrategy -> RoutingStrategy -> Bool
$c/= :: RoutingStrategy -> RoutingStrategy -> Bool
== :: RoutingStrategy -> RoutingStrategy -> Bool
$c== :: RoutingStrategy -> RoutingStrategy -> Bool
Prelude.Eq, ReadPrec [RoutingStrategy]
ReadPrec RoutingStrategy
Int -> ReadS RoutingStrategy
ReadS [RoutingStrategy]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RoutingStrategy]
$creadListPrec :: ReadPrec [RoutingStrategy]
readPrec :: ReadPrec RoutingStrategy
$creadPrec :: ReadPrec RoutingStrategy
readList :: ReadS [RoutingStrategy]
$creadList :: ReadS [RoutingStrategy]
readsPrec :: Int -> ReadS RoutingStrategy
$creadsPrec :: Int -> ReadS RoutingStrategy
Prelude.Read, Int -> RoutingStrategy -> ShowS
[RoutingStrategy] -> ShowS
RoutingStrategy -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RoutingStrategy] -> ShowS
$cshowList :: [RoutingStrategy] -> ShowS
show :: RoutingStrategy -> String
$cshow :: RoutingStrategy -> String
showsPrec :: Int -> RoutingStrategy -> ShowS
$cshowsPrec :: Int -> RoutingStrategy -> ShowS
Prelude.Show, forall x. Rep RoutingStrategy x -> RoutingStrategy
forall x. RoutingStrategy -> Rep RoutingStrategy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RoutingStrategy x -> RoutingStrategy
$cfrom :: forall x. RoutingStrategy -> Rep RoutingStrategy x
Prelude.Generic)

-- |
-- Create a value of 'RoutingStrategy' 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:
--
-- 'fleetId', 'routingStrategy_fleetId' - A unique identifier for the fleet that the alias points to. This value
-- is the fleet ID, not the fleet ARN.
--
-- 'message', 'routingStrategy_message' - The message text to be used with a terminal routing strategy.
--
-- 'type'', 'routingStrategy_type' - The type of routing strategy for the alias.
--
-- Possible routing types include the following:
--
-- -   __SIMPLE__ - The alias resolves to one specific fleet. Use this type
--     when routing to active fleets.
--
-- -   __TERMINAL__ - The alias does not resolve to a fleet but instead can
--     be used to display a message to the user. A terminal alias throws a
--     TerminalRoutingStrategyException with the message embedded.
newRoutingStrategy ::
  RoutingStrategy
newRoutingStrategy :: RoutingStrategy
newRoutingStrategy =
  RoutingStrategy'
    { $sel:fleetId:RoutingStrategy' :: Maybe Text
fleetId = forall a. Maybe a
Prelude.Nothing,
      $sel:message:RoutingStrategy' :: Maybe Text
message = forall a. Maybe a
Prelude.Nothing,
      $sel:type':RoutingStrategy' :: Maybe RoutingStrategyType
type' = forall a. Maybe a
Prelude.Nothing
    }

-- | A unique identifier for the fleet that the alias points to. This value
-- is the fleet ID, not the fleet ARN.
routingStrategy_fleetId :: Lens.Lens' RoutingStrategy (Prelude.Maybe Prelude.Text)
routingStrategy_fleetId :: Lens' RoutingStrategy (Maybe Text)
routingStrategy_fleetId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RoutingStrategy' {Maybe Text
fleetId :: Maybe Text
$sel:fleetId:RoutingStrategy' :: RoutingStrategy -> Maybe Text
fleetId} -> Maybe Text
fleetId) (\s :: RoutingStrategy
s@RoutingStrategy' {} Maybe Text
a -> RoutingStrategy
s {$sel:fleetId:RoutingStrategy' :: Maybe Text
fleetId = Maybe Text
a} :: RoutingStrategy)

-- | The message text to be used with a terminal routing strategy.
routingStrategy_message :: Lens.Lens' RoutingStrategy (Prelude.Maybe Prelude.Text)
routingStrategy_message :: Lens' RoutingStrategy (Maybe Text)
routingStrategy_message = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RoutingStrategy' {Maybe Text
message :: Maybe Text
$sel:message:RoutingStrategy' :: RoutingStrategy -> Maybe Text
message} -> Maybe Text
message) (\s :: RoutingStrategy
s@RoutingStrategy' {} Maybe Text
a -> RoutingStrategy
s {$sel:message:RoutingStrategy' :: Maybe Text
message = Maybe Text
a} :: RoutingStrategy)

-- | The type of routing strategy for the alias.
--
-- Possible routing types include the following:
--
-- -   __SIMPLE__ - The alias resolves to one specific fleet. Use this type
--     when routing to active fleets.
--
-- -   __TERMINAL__ - The alias does not resolve to a fleet but instead can
--     be used to display a message to the user. A terminal alias throws a
--     TerminalRoutingStrategyException with the message embedded.
routingStrategy_type :: Lens.Lens' RoutingStrategy (Prelude.Maybe RoutingStrategyType)
routingStrategy_type :: Lens' RoutingStrategy (Maybe RoutingStrategyType)
routingStrategy_type = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RoutingStrategy' {Maybe RoutingStrategyType
type' :: Maybe RoutingStrategyType
$sel:type':RoutingStrategy' :: RoutingStrategy -> Maybe RoutingStrategyType
type'} -> Maybe RoutingStrategyType
type') (\s :: RoutingStrategy
s@RoutingStrategy' {} Maybe RoutingStrategyType
a -> RoutingStrategy
s {$sel:type':RoutingStrategy' :: Maybe RoutingStrategyType
type' = Maybe RoutingStrategyType
a} :: RoutingStrategy)

instance Data.FromJSON RoutingStrategy where
  parseJSON :: Value -> Parser RoutingStrategy
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"RoutingStrategy"
      ( \Object
x ->
          Maybe Text
-> Maybe Text -> Maybe RoutingStrategyType -> RoutingStrategy
RoutingStrategy'
            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
"FleetId")
            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
"Message")
            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
"Type")
      )

instance Prelude.Hashable RoutingStrategy where
  hashWithSalt :: Int -> RoutingStrategy -> Int
hashWithSalt Int
_salt RoutingStrategy' {Maybe Text
Maybe RoutingStrategyType
type' :: Maybe RoutingStrategyType
message :: Maybe Text
fleetId :: Maybe Text
$sel:type':RoutingStrategy' :: RoutingStrategy -> Maybe RoutingStrategyType
$sel:message:RoutingStrategy' :: RoutingStrategy -> Maybe Text
$sel:fleetId:RoutingStrategy' :: RoutingStrategy -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
fleetId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
message
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe RoutingStrategyType
type'

instance Prelude.NFData RoutingStrategy where
  rnf :: RoutingStrategy -> ()
rnf RoutingStrategy' {Maybe Text
Maybe RoutingStrategyType
type' :: Maybe RoutingStrategyType
message :: Maybe Text
fleetId :: Maybe Text
$sel:type':RoutingStrategy' :: RoutingStrategy -> Maybe RoutingStrategyType
$sel:message:RoutingStrategy' :: RoutingStrategy -> Maybe Text
$sel:fleetId:RoutingStrategy' :: RoutingStrategy -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
fleetId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
message
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe RoutingStrategyType
type'

instance Data.ToJSON RoutingStrategy where
  toJSON :: RoutingStrategy -> Value
toJSON RoutingStrategy' {Maybe Text
Maybe RoutingStrategyType
type' :: Maybe RoutingStrategyType
message :: Maybe Text
fleetId :: Maybe Text
$sel:type':RoutingStrategy' :: RoutingStrategy -> Maybe RoutingStrategyType
$sel:message:RoutingStrategy' :: RoutingStrategy -> Maybe Text
$sel:fleetId:RoutingStrategy' :: RoutingStrategy -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"FleetId" 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 Text
fleetId,
            (Key
"Message" 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 Text
message,
            (Key
"Type" 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 RoutingStrategyType
type'
          ]
      )