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

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | A set of instructions for launching server processes on each instance in
-- a fleet. Server processes run either an executable in a custom game
-- build or a Realtime Servers script. Server process configurations are
-- part of a fleet\'s runtime configuration.
--
-- /See:/ 'newServerProcess' smart constructor.
data ServerProcess = ServerProcess'
  { -- | An optional list of parameters to pass to the server executable or
    -- Realtime script on launch.
    ServerProcess -> Maybe Text
parameters :: Prelude.Maybe Prelude.Text,
    -- | The location of a game build executable or the Realtime script file that
    -- contains the @Init()@ function. Game builds and Realtime scripts are
    -- installed on instances at the root:
    --
    -- -   Windows (custom game builds only): @C:\\game@. Example:
    --     \"@C:\\game\\MyGame\\server.exe@\"
    --
    -- -   Linux: @\/local\/game@. Examples:
    --     \"@\/local\/game\/MyGame\/server.exe@\" or
    --     \"@\/local\/game\/MyRealtimeScript.js@\"
    ServerProcess -> Text
launchPath :: Prelude.Text,
    -- | The number of server processes using this configuration that run
    -- concurrently on each instance.
    ServerProcess -> Natural
concurrentExecutions :: Prelude.Natural
  }
  deriving (ServerProcess -> ServerProcess -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ServerProcess -> ServerProcess -> Bool
$c/= :: ServerProcess -> ServerProcess -> Bool
== :: ServerProcess -> ServerProcess -> Bool
$c== :: ServerProcess -> ServerProcess -> Bool
Prelude.Eq, ReadPrec [ServerProcess]
ReadPrec ServerProcess
Int -> ReadS ServerProcess
ReadS [ServerProcess]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ServerProcess]
$creadListPrec :: ReadPrec [ServerProcess]
readPrec :: ReadPrec ServerProcess
$creadPrec :: ReadPrec ServerProcess
readList :: ReadS [ServerProcess]
$creadList :: ReadS [ServerProcess]
readsPrec :: Int -> ReadS ServerProcess
$creadsPrec :: Int -> ReadS ServerProcess
Prelude.Read, Int -> ServerProcess -> ShowS
[ServerProcess] -> ShowS
ServerProcess -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ServerProcess] -> ShowS
$cshowList :: [ServerProcess] -> ShowS
show :: ServerProcess -> String
$cshow :: ServerProcess -> String
showsPrec :: Int -> ServerProcess -> ShowS
$cshowsPrec :: Int -> ServerProcess -> ShowS
Prelude.Show, forall x. Rep ServerProcess x -> ServerProcess
forall x. ServerProcess -> Rep ServerProcess x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ServerProcess x -> ServerProcess
$cfrom :: forall x. ServerProcess -> Rep ServerProcess x
Prelude.Generic)

-- |
-- Create a value of 'ServerProcess' 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:
--
-- 'parameters', 'serverProcess_parameters' - An optional list of parameters to pass to the server executable or
-- Realtime script on launch.
--
-- 'launchPath', 'serverProcess_launchPath' - The location of a game build executable or the Realtime script file that
-- contains the @Init()@ function. Game builds and Realtime scripts are
-- installed on instances at the root:
--
-- -   Windows (custom game builds only): @C:\\game@. Example:
--     \"@C:\\game\\MyGame\\server.exe@\"
--
-- -   Linux: @\/local\/game@. Examples:
--     \"@\/local\/game\/MyGame\/server.exe@\" or
--     \"@\/local\/game\/MyRealtimeScript.js@\"
--
-- 'concurrentExecutions', 'serverProcess_concurrentExecutions' - The number of server processes using this configuration that run
-- concurrently on each instance.
newServerProcess ::
  -- | 'launchPath'
  Prelude.Text ->
  -- | 'concurrentExecutions'
  Prelude.Natural ->
  ServerProcess
newServerProcess :: Text -> Natural -> ServerProcess
newServerProcess Text
pLaunchPath_ Natural
pConcurrentExecutions_ =
  ServerProcess'
    { $sel:parameters:ServerProcess' :: Maybe Text
parameters = forall a. Maybe a
Prelude.Nothing,
      $sel:launchPath:ServerProcess' :: Text
launchPath = Text
pLaunchPath_,
      $sel:concurrentExecutions:ServerProcess' :: Natural
concurrentExecutions = Natural
pConcurrentExecutions_
    }

-- | An optional list of parameters to pass to the server executable or
-- Realtime script on launch.
serverProcess_parameters :: Lens.Lens' ServerProcess (Prelude.Maybe Prelude.Text)
serverProcess_parameters :: Lens' ServerProcess (Maybe Text)
serverProcess_parameters = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ServerProcess' {Maybe Text
parameters :: Maybe Text
$sel:parameters:ServerProcess' :: ServerProcess -> Maybe Text
parameters} -> Maybe Text
parameters) (\s :: ServerProcess
s@ServerProcess' {} Maybe Text
a -> ServerProcess
s {$sel:parameters:ServerProcess' :: Maybe Text
parameters = Maybe Text
a} :: ServerProcess)

-- | The location of a game build executable or the Realtime script file that
-- contains the @Init()@ function. Game builds and Realtime scripts are
-- installed on instances at the root:
--
-- -   Windows (custom game builds only): @C:\\game@. Example:
--     \"@C:\\game\\MyGame\\server.exe@\"
--
-- -   Linux: @\/local\/game@. Examples:
--     \"@\/local\/game\/MyGame\/server.exe@\" or
--     \"@\/local\/game\/MyRealtimeScript.js@\"
serverProcess_launchPath :: Lens.Lens' ServerProcess Prelude.Text
serverProcess_launchPath :: Lens' ServerProcess Text
serverProcess_launchPath = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ServerProcess' {Text
launchPath :: Text
$sel:launchPath:ServerProcess' :: ServerProcess -> Text
launchPath} -> Text
launchPath) (\s :: ServerProcess
s@ServerProcess' {} Text
a -> ServerProcess
s {$sel:launchPath:ServerProcess' :: Text
launchPath = Text
a} :: ServerProcess)

-- | The number of server processes using this configuration that run
-- concurrently on each instance.
serverProcess_concurrentExecutions :: Lens.Lens' ServerProcess Prelude.Natural
serverProcess_concurrentExecutions :: Lens' ServerProcess Natural
serverProcess_concurrentExecutions = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ServerProcess' {Natural
concurrentExecutions :: Natural
$sel:concurrentExecutions:ServerProcess' :: ServerProcess -> Natural
concurrentExecutions} -> Natural
concurrentExecutions) (\s :: ServerProcess
s@ServerProcess' {} Natural
a -> ServerProcess
s {$sel:concurrentExecutions:ServerProcess' :: Natural
concurrentExecutions = Natural
a} :: ServerProcess)

instance Data.FromJSON ServerProcess where
  parseJSON :: Value -> Parser ServerProcess
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ServerProcess"
      ( \Object
x ->
          Maybe Text -> Text -> Natural -> ServerProcess
ServerProcess'
            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
"Parameters")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"LaunchPath")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"ConcurrentExecutions")
      )

instance Prelude.Hashable ServerProcess where
  hashWithSalt :: Int -> ServerProcess -> Int
hashWithSalt Int
_salt ServerProcess' {Natural
Maybe Text
Text
concurrentExecutions :: Natural
launchPath :: Text
parameters :: Maybe Text
$sel:concurrentExecutions:ServerProcess' :: ServerProcess -> Natural
$sel:launchPath:ServerProcess' :: ServerProcess -> Text
$sel:parameters:ServerProcess' :: ServerProcess -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
parameters
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
launchPath
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Natural
concurrentExecutions

instance Prelude.NFData ServerProcess where
  rnf :: ServerProcess -> ()
rnf ServerProcess' {Natural
Maybe Text
Text
concurrentExecutions :: Natural
launchPath :: Text
parameters :: Maybe Text
$sel:concurrentExecutions:ServerProcess' :: ServerProcess -> Natural
$sel:launchPath:ServerProcess' :: ServerProcess -> Text
$sel:parameters:ServerProcess' :: ServerProcess -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
parameters
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
launchPath
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Natural
concurrentExecutions

instance Data.ToJSON ServerProcess where
  toJSON :: ServerProcess -> Value
toJSON ServerProcess' {Natural
Maybe Text
Text
concurrentExecutions :: Natural
launchPath :: Text
parameters :: Maybe Text
$sel:concurrentExecutions:ServerProcess' :: ServerProcess -> Natural
$sel:launchPath:ServerProcess' :: ServerProcess -> Text
$sel:parameters:ServerProcess' :: ServerProcess -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Parameters" 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
parameters,
            forall a. a -> Maybe a
Prelude.Just (Key
"LaunchPath" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
launchPath),
            forall a. a -> Maybe a
Prelude.Just
              ( Key
"ConcurrentExecutions"
                  forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Natural
concurrentExecutions
              )
          ]
      )