{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.GamesParks.StartStageDeployment
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Deploys a snapshot to the stage and creates a new game runtime.
--
-- After you call this operation, you can check the deployment status by
-- using @GetStageDeployment@.
--
-- If there are any players connected to the previous game runtime, then
-- both runtimes persist. Existing connections to the previous runtime are
-- maintained. When players disconnect and reconnect, they connect to the
-- new runtime. After there are no connections to the previous game
-- runtime, it is deleted.
module Amazonka.GamesParks.StartStageDeployment
  ( -- * Creating a Request
    StartStageDeployment (..),
    newStartStageDeployment,

    -- * Request Lenses
    startStageDeployment_clientToken,
    startStageDeployment_gameName,
    startStageDeployment_snapshotId,
    startStageDeployment_stageName,

    -- * Destructuring the Response
    StartStageDeploymentResponse (..),
    newStartStageDeploymentResponse,

    -- * Response Lenses
    startStageDeploymentResponse_stageDeployment,
    startStageDeploymentResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.GamesParks.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newStartStageDeployment' smart constructor.
data StartStageDeployment = StartStageDeployment'
  { -- | A client-defined token. With an active client token in the request, this
    -- action is idempotent.
    StartStageDeployment -> Maybe Text
clientToken :: Prelude.Maybe Prelude.Text,
    -- | The name of the game.
    StartStageDeployment -> Text
gameName :: Prelude.Text,
    -- | The identifier of the snapshot to deploy.
    StartStageDeployment -> Text
snapshotId :: Prelude.Text,
    -- | The name of the stage to deploy the snapshot onto.
    StartStageDeployment -> Text
stageName :: Prelude.Text
  }
  deriving (StartStageDeployment -> StartStageDeployment -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StartStageDeployment -> StartStageDeployment -> Bool
$c/= :: StartStageDeployment -> StartStageDeployment -> Bool
== :: StartStageDeployment -> StartStageDeployment -> Bool
$c== :: StartStageDeployment -> StartStageDeployment -> Bool
Prelude.Eq, ReadPrec [StartStageDeployment]
ReadPrec StartStageDeployment
Int -> ReadS StartStageDeployment
ReadS [StartStageDeployment]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StartStageDeployment]
$creadListPrec :: ReadPrec [StartStageDeployment]
readPrec :: ReadPrec StartStageDeployment
$creadPrec :: ReadPrec StartStageDeployment
readList :: ReadS [StartStageDeployment]
$creadList :: ReadS [StartStageDeployment]
readsPrec :: Int -> ReadS StartStageDeployment
$creadsPrec :: Int -> ReadS StartStageDeployment
Prelude.Read, Int -> StartStageDeployment -> ShowS
[StartStageDeployment] -> ShowS
StartStageDeployment -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StartStageDeployment] -> ShowS
$cshowList :: [StartStageDeployment] -> ShowS
show :: StartStageDeployment -> String
$cshow :: StartStageDeployment -> String
showsPrec :: Int -> StartStageDeployment -> ShowS
$cshowsPrec :: Int -> StartStageDeployment -> ShowS
Prelude.Show, forall x. Rep StartStageDeployment x -> StartStageDeployment
forall x. StartStageDeployment -> Rep StartStageDeployment x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StartStageDeployment x -> StartStageDeployment
$cfrom :: forall x. StartStageDeployment -> Rep StartStageDeployment x
Prelude.Generic)

-- |
-- Create a value of 'StartStageDeployment' 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:
--
-- 'clientToken', 'startStageDeployment_clientToken' - A client-defined token. With an active client token in the request, this
-- action is idempotent.
--
-- 'gameName', 'startStageDeployment_gameName' - The name of the game.
--
-- 'snapshotId', 'startStageDeployment_snapshotId' - The identifier of the snapshot to deploy.
--
-- 'stageName', 'startStageDeployment_stageName' - The name of the stage to deploy the snapshot onto.
newStartStageDeployment ::
  -- | 'gameName'
  Prelude.Text ->
  -- | 'snapshotId'
  Prelude.Text ->
  -- | 'stageName'
  Prelude.Text ->
  StartStageDeployment
newStartStageDeployment :: Text -> Text -> Text -> StartStageDeployment
newStartStageDeployment
  Text
pGameName_
  Text
pSnapshotId_
  Text
pStageName_ =
    StartStageDeployment'
      { $sel:clientToken:StartStageDeployment' :: Maybe Text
clientToken =
          forall a. Maybe a
Prelude.Nothing,
        $sel:gameName:StartStageDeployment' :: Text
gameName = Text
pGameName_,
        $sel:snapshotId:StartStageDeployment' :: Text
snapshotId = Text
pSnapshotId_,
        $sel:stageName:StartStageDeployment' :: Text
stageName = Text
pStageName_
      }

-- | A client-defined token. With an active client token in the request, this
-- action is idempotent.
startStageDeployment_clientToken :: Lens.Lens' StartStageDeployment (Prelude.Maybe Prelude.Text)
startStageDeployment_clientToken :: Lens' StartStageDeployment (Maybe Text)
startStageDeployment_clientToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartStageDeployment' {Maybe Text
clientToken :: Maybe Text
$sel:clientToken:StartStageDeployment' :: StartStageDeployment -> Maybe Text
clientToken} -> Maybe Text
clientToken) (\s :: StartStageDeployment
s@StartStageDeployment' {} Maybe Text
a -> StartStageDeployment
s {$sel:clientToken:StartStageDeployment' :: Maybe Text
clientToken = Maybe Text
a} :: StartStageDeployment)

-- | The name of the game.
startStageDeployment_gameName :: Lens.Lens' StartStageDeployment Prelude.Text
startStageDeployment_gameName :: Lens' StartStageDeployment Text
startStageDeployment_gameName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartStageDeployment' {Text
gameName :: Text
$sel:gameName:StartStageDeployment' :: StartStageDeployment -> Text
gameName} -> Text
gameName) (\s :: StartStageDeployment
s@StartStageDeployment' {} Text
a -> StartStageDeployment
s {$sel:gameName:StartStageDeployment' :: Text
gameName = Text
a} :: StartStageDeployment)

-- | The identifier of the snapshot to deploy.
startStageDeployment_snapshotId :: Lens.Lens' StartStageDeployment Prelude.Text
startStageDeployment_snapshotId :: Lens' StartStageDeployment Text
startStageDeployment_snapshotId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartStageDeployment' {Text
snapshotId :: Text
$sel:snapshotId:StartStageDeployment' :: StartStageDeployment -> Text
snapshotId} -> Text
snapshotId) (\s :: StartStageDeployment
s@StartStageDeployment' {} Text
a -> StartStageDeployment
s {$sel:snapshotId:StartStageDeployment' :: Text
snapshotId = Text
a} :: StartStageDeployment)

-- | The name of the stage to deploy the snapshot onto.
startStageDeployment_stageName :: Lens.Lens' StartStageDeployment Prelude.Text
startStageDeployment_stageName :: Lens' StartStageDeployment Text
startStageDeployment_stageName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartStageDeployment' {Text
stageName :: Text
$sel:stageName:StartStageDeployment' :: StartStageDeployment -> Text
stageName} -> Text
stageName) (\s :: StartStageDeployment
s@StartStageDeployment' {} Text
a -> StartStageDeployment
s {$sel:stageName:StartStageDeployment' :: Text
stageName = Text
a} :: StartStageDeployment)

instance Core.AWSRequest StartStageDeployment where
  type
    AWSResponse StartStageDeployment =
      StartStageDeploymentResponse
  request :: (Service -> Service)
-> StartStageDeployment -> Request StartStageDeployment
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy StartStageDeployment
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse StartStageDeployment)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe StageDeploymentDetails -> Int -> StartStageDeploymentResponse
StartStageDeploymentResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"StageDeployment")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable StartStageDeployment where
  hashWithSalt :: Int -> StartStageDeployment -> Int
hashWithSalt Int
_salt StartStageDeployment' {Maybe Text
Text
stageName :: Text
snapshotId :: Text
gameName :: Text
clientToken :: Maybe Text
$sel:stageName:StartStageDeployment' :: StartStageDeployment -> Text
$sel:snapshotId:StartStageDeployment' :: StartStageDeployment -> Text
$sel:gameName:StartStageDeployment' :: StartStageDeployment -> Text
$sel:clientToken:StartStageDeployment' :: StartStageDeployment -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
clientToken
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
gameName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
snapshotId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
stageName

instance Prelude.NFData StartStageDeployment where
  rnf :: StartStageDeployment -> ()
rnf StartStageDeployment' {Maybe Text
Text
stageName :: Text
snapshotId :: Text
gameName :: Text
clientToken :: Maybe Text
$sel:stageName:StartStageDeployment' :: StartStageDeployment -> Text
$sel:snapshotId:StartStageDeployment' :: StartStageDeployment -> Text
$sel:gameName:StartStageDeployment' :: StartStageDeployment -> Text
$sel:clientToken:StartStageDeployment' :: StartStageDeployment -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
clientToken
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
gameName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
snapshotId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
stageName

instance Data.ToHeaders StartStageDeployment where
  toHeaders :: StartStageDeployment -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON StartStageDeployment where
  toJSON :: StartStageDeployment -> Value
toJSON StartStageDeployment' {Maybe Text
Text
stageName :: Text
snapshotId :: Text
gameName :: Text
clientToken :: Maybe Text
$sel:stageName:StartStageDeployment' :: StartStageDeployment -> Text
$sel:snapshotId:StartStageDeployment' :: StartStageDeployment -> Text
$sel:gameName:StartStageDeployment' :: StartStageDeployment -> Text
$sel:clientToken:StartStageDeployment' :: StartStageDeployment -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"ClientToken" 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
clientToken,
            forall a. a -> Maybe a
Prelude.Just (Key
"SnapshotId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
snapshotId)
          ]
      )

instance Data.ToPath StartStageDeployment where
  toPath :: StartStageDeployment -> ByteString
toPath StartStageDeployment' {Maybe Text
Text
stageName :: Text
snapshotId :: Text
gameName :: Text
clientToken :: Maybe Text
$sel:stageName:StartStageDeployment' :: StartStageDeployment -> Text
$sel:snapshotId:StartStageDeployment' :: StartStageDeployment -> Text
$sel:gameName:StartStageDeployment' :: StartStageDeployment -> Text
$sel:clientToken:StartStageDeployment' :: StartStageDeployment -> Maybe Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/game/",
        forall a. ToByteString a => a -> ByteString
Data.toBS Text
gameName,
        ByteString
"/stage/",
        forall a. ToByteString a => a -> ByteString
Data.toBS Text
stageName,
        ByteString
"/deployment"
      ]

instance Data.ToQuery StartStageDeployment where
  toQuery :: StartStageDeployment -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newStartStageDeploymentResponse' smart constructor.
data StartStageDeploymentResponse = StartStageDeploymentResponse'
  { -- | Properties that describe the stage deployment.
    StartStageDeploymentResponse -> Maybe StageDeploymentDetails
stageDeployment :: Prelude.Maybe StageDeploymentDetails,
    -- | The response's http status code.
    StartStageDeploymentResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (StartStageDeploymentResponse
-> StartStageDeploymentResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StartStageDeploymentResponse
-> StartStageDeploymentResponse -> Bool
$c/= :: StartStageDeploymentResponse
-> StartStageDeploymentResponse -> Bool
== :: StartStageDeploymentResponse
-> StartStageDeploymentResponse -> Bool
$c== :: StartStageDeploymentResponse
-> StartStageDeploymentResponse -> Bool
Prelude.Eq, ReadPrec [StartStageDeploymentResponse]
ReadPrec StartStageDeploymentResponse
Int -> ReadS StartStageDeploymentResponse
ReadS [StartStageDeploymentResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StartStageDeploymentResponse]
$creadListPrec :: ReadPrec [StartStageDeploymentResponse]
readPrec :: ReadPrec StartStageDeploymentResponse
$creadPrec :: ReadPrec StartStageDeploymentResponse
readList :: ReadS [StartStageDeploymentResponse]
$creadList :: ReadS [StartStageDeploymentResponse]
readsPrec :: Int -> ReadS StartStageDeploymentResponse
$creadsPrec :: Int -> ReadS StartStageDeploymentResponse
Prelude.Read, Int -> StartStageDeploymentResponse -> ShowS
[StartStageDeploymentResponse] -> ShowS
StartStageDeploymentResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StartStageDeploymentResponse] -> ShowS
$cshowList :: [StartStageDeploymentResponse] -> ShowS
show :: StartStageDeploymentResponse -> String
$cshow :: StartStageDeploymentResponse -> String
showsPrec :: Int -> StartStageDeploymentResponse -> ShowS
$cshowsPrec :: Int -> StartStageDeploymentResponse -> ShowS
Prelude.Show, forall x.
Rep StartStageDeploymentResponse x -> StartStageDeploymentResponse
forall x.
StartStageDeploymentResponse -> Rep StartStageDeploymentResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep StartStageDeploymentResponse x -> StartStageDeploymentResponse
$cfrom :: forall x.
StartStageDeploymentResponse -> Rep StartStageDeploymentResponse x
Prelude.Generic)

-- |
-- Create a value of 'StartStageDeploymentResponse' 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:
--
-- 'stageDeployment', 'startStageDeploymentResponse_stageDeployment' - Properties that describe the stage deployment.
--
-- 'httpStatus', 'startStageDeploymentResponse_httpStatus' - The response's http status code.
newStartStageDeploymentResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  StartStageDeploymentResponse
newStartStageDeploymentResponse :: Int -> StartStageDeploymentResponse
newStartStageDeploymentResponse Int
pHttpStatus_ =
  StartStageDeploymentResponse'
    { $sel:stageDeployment:StartStageDeploymentResponse' :: Maybe StageDeploymentDetails
stageDeployment =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:StartStageDeploymentResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Properties that describe the stage deployment.
startStageDeploymentResponse_stageDeployment :: Lens.Lens' StartStageDeploymentResponse (Prelude.Maybe StageDeploymentDetails)
startStageDeploymentResponse_stageDeployment :: Lens' StartStageDeploymentResponse (Maybe StageDeploymentDetails)
startStageDeploymentResponse_stageDeployment = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartStageDeploymentResponse' {Maybe StageDeploymentDetails
stageDeployment :: Maybe StageDeploymentDetails
$sel:stageDeployment:StartStageDeploymentResponse' :: StartStageDeploymentResponse -> Maybe StageDeploymentDetails
stageDeployment} -> Maybe StageDeploymentDetails
stageDeployment) (\s :: StartStageDeploymentResponse
s@StartStageDeploymentResponse' {} Maybe StageDeploymentDetails
a -> StartStageDeploymentResponse
s {$sel:stageDeployment:StartStageDeploymentResponse' :: Maybe StageDeploymentDetails
stageDeployment = Maybe StageDeploymentDetails
a} :: StartStageDeploymentResponse)

-- | The response's http status code.
startStageDeploymentResponse_httpStatus :: Lens.Lens' StartStageDeploymentResponse Prelude.Int
startStageDeploymentResponse_httpStatus :: Lens' StartStageDeploymentResponse Int
startStageDeploymentResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartStageDeploymentResponse' {Int
httpStatus :: Int
$sel:httpStatus:StartStageDeploymentResponse' :: StartStageDeploymentResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: StartStageDeploymentResponse
s@StartStageDeploymentResponse' {} Int
a -> StartStageDeploymentResponse
s {$sel:httpStatus:StartStageDeploymentResponse' :: Int
httpStatus = Int
a} :: StartStageDeploymentResponse)

instance Prelude.NFData StartStageDeploymentResponse where
  rnf :: StartStageDeploymentResponse -> ()
rnf StartStageDeploymentResponse' {Int
Maybe StageDeploymentDetails
httpStatus :: Int
stageDeployment :: Maybe StageDeploymentDetails
$sel:httpStatus:StartStageDeploymentResponse' :: StartStageDeploymentResponse -> Int
$sel:stageDeployment:StartStageDeploymentResponse' :: StartStageDeploymentResponse -> Maybe StageDeploymentDetails
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe StageDeploymentDetails
stageDeployment
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus