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

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

-- | The routing configuration for a fleet alias.
--
-- __Related actions__
--
-- CreateAlias | ListAliases | DescribeAlias | UpdateAlias | DeleteAlias |
-- ResolveAlias |
-- <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'
  { -- | 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 RoutingStrategy message
    --     embedded.
    RoutingStrategy -> Maybe RoutingStrategyType
type' :: Prelude.Maybe RoutingStrategyType,
    -- | The message text to be used with a terminal routing strategy.
    RoutingStrategy -> Maybe Text
message :: Prelude.Maybe Prelude.Text,
    -- | 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
  }
  deriving (RoutingStrategy -> RoutingStrategy -> Bool
(RoutingStrategy -> RoutingStrategy -> Bool)
-> (RoutingStrategy -> RoutingStrategy -> Bool)
-> Eq RoutingStrategy
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]
(Int -> ReadS RoutingStrategy)
-> ReadS [RoutingStrategy]
-> ReadPrec RoutingStrategy
-> ReadPrec [RoutingStrategy]
-> Read 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
(Int -> RoutingStrategy -> ShowS)
-> (RoutingStrategy -> String)
-> ([RoutingStrategy] -> ShowS)
-> Show RoutingStrategy
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. RoutingStrategy -> Rep RoutingStrategy x)
-> (forall x. Rep RoutingStrategy x -> RoutingStrategy)
-> Generic RoutingStrategy
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:
--
-- '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 RoutingStrategy message
--     embedded.
--
-- 'message', 'routingStrategy_message' - The message text to be used with a terminal routing strategy.
--
-- 'fleetId', 'routingStrategy_fleetId' - A unique identifier for the fleet that the alias points to. This value
-- is the fleet ID, not the fleet ARN.
newRoutingStrategy ::
  RoutingStrategy
newRoutingStrategy :: RoutingStrategy
newRoutingStrategy =
  RoutingStrategy' :: Maybe RoutingStrategyType
-> Maybe Text -> Maybe Text -> RoutingStrategy
RoutingStrategy'
    { $sel:type':RoutingStrategy' :: Maybe RoutingStrategyType
type' = Maybe RoutingStrategyType
forall a. Maybe a
Prelude.Nothing,
      $sel:message:RoutingStrategy' :: Maybe Text
message = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:fleetId:RoutingStrategy' :: Maybe Text
fleetId = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | 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 RoutingStrategy message
--     embedded.
routingStrategy_type :: Lens.Lens' RoutingStrategy (Prelude.Maybe RoutingStrategyType)
routingStrategy_type :: (Maybe RoutingStrategyType -> f (Maybe RoutingStrategyType))
-> RoutingStrategy -> f RoutingStrategy
routingStrategy_type = (RoutingStrategy -> Maybe RoutingStrategyType)
-> (RoutingStrategy
    -> Maybe RoutingStrategyType -> RoutingStrategy)
-> Lens
     RoutingStrategy
     RoutingStrategy
     (Maybe RoutingStrategyType)
     (Maybe RoutingStrategyType)
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)

-- | The message text to be used with a terminal routing strategy.
routingStrategy_message :: Lens.Lens' RoutingStrategy (Prelude.Maybe Prelude.Text)
routingStrategy_message :: (Maybe Text -> f (Maybe Text))
-> RoutingStrategy -> f RoutingStrategy
routingStrategy_message = (RoutingStrategy -> Maybe Text)
-> (RoutingStrategy -> Maybe Text -> RoutingStrategy)
-> Lens RoutingStrategy RoutingStrategy (Maybe Text) (Maybe Text)
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)

-- | 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 :: (Maybe Text -> f (Maybe Text))
-> RoutingStrategy -> f RoutingStrategy
routingStrategy_fleetId = (RoutingStrategy -> Maybe Text)
-> (RoutingStrategy -> Maybe Text -> RoutingStrategy)
-> Lens RoutingStrategy RoutingStrategy (Maybe Text) (Maybe Text)
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)

instance Core.FromJSON RoutingStrategy where
  parseJSON :: Value -> Parser RoutingStrategy
parseJSON =
    String
-> (Object -> Parser RoutingStrategy)
-> Value
-> Parser RoutingStrategy
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"RoutingStrategy"
      ( \Object
x ->
          Maybe RoutingStrategyType
-> Maybe Text -> Maybe Text -> RoutingStrategy
RoutingStrategy'
            (Maybe RoutingStrategyType
 -> Maybe Text -> Maybe Text -> RoutingStrategy)
-> Parser (Maybe RoutingStrategyType)
-> Parser (Maybe Text -> Maybe Text -> RoutingStrategy)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe RoutingStrategyType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Type")
            Parser (Maybe Text -> Maybe Text -> RoutingStrategy)
-> Parser (Maybe Text) -> Parser (Maybe Text -> RoutingStrategy)
forall (f :: * -> *) a b. Applicative f => 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
"Message")
            Parser (Maybe Text -> RoutingStrategy)
-> Parser (Maybe Text) -> Parser RoutingStrategy
forall (f :: * -> *) a b. Applicative f => 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
"FleetId")
      )

instance Prelude.Hashable RoutingStrategy

instance Prelude.NFData RoutingStrategy

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