{-# 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.CreateGame
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Creates a new game with an empty configuration. After creating your
-- game, you can update the configuration using @UpdateGameConfiguration@
-- or @ImportGameConfiguration@.
module Amazonka.GamesParks.CreateGame
  ( -- * Creating a Request
    CreateGame (..),
    newCreateGame,

    -- * Request Lenses
    createGame_clientToken,
    createGame_description,
    createGame_tags,
    createGame_gameName,

    -- * Destructuring the Response
    CreateGameResponse (..),
    newCreateGameResponse,

    -- * Response Lenses
    createGameResponse_game,
    createGameResponse_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:/ 'newCreateGame' smart constructor.
data CreateGame = CreateGame'
  { -- | A client-defined token. With an active client token in the request, this
    -- action is idempotent.
    CreateGame -> Maybe Text
clientToken :: Prelude.Maybe Prelude.Text,
    -- | The description of the game.
    CreateGame -> Maybe Text
description :: Prelude.Maybe Prelude.Text,
    -- | The list of tags to apply to the game.
    CreateGame -> Maybe (HashMap Text Text)
tags :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | The name of the game.
    CreateGame -> Text
gameName :: Prelude.Text
  }
  deriving (CreateGame -> CreateGame -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateGame -> CreateGame -> Bool
$c/= :: CreateGame -> CreateGame -> Bool
== :: CreateGame -> CreateGame -> Bool
$c== :: CreateGame -> CreateGame -> Bool
Prelude.Eq, ReadPrec [CreateGame]
ReadPrec CreateGame
Int -> ReadS CreateGame
ReadS [CreateGame]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateGame]
$creadListPrec :: ReadPrec [CreateGame]
readPrec :: ReadPrec CreateGame
$creadPrec :: ReadPrec CreateGame
readList :: ReadS [CreateGame]
$creadList :: ReadS [CreateGame]
readsPrec :: Int -> ReadS CreateGame
$creadsPrec :: Int -> ReadS CreateGame
Prelude.Read, Int -> CreateGame -> ShowS
[CreateGame] -> ShowS
CreateGame -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateGame] -> ShowS
$cshowList :: [CreateGame] -> ShowS
show :: CreateGame -> String
$cshow :: CreateGame -> String
showsPrec :: Int -> CreateGame -> ShowS
$cshowsPrec :: Int -> CreateGame -> ShowS
Prelude.Show, forall x. Rep CreateGame x -> CreateGame
forall x. CreateGame -> Rep CreateGame x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateGame x -> CreateGame
$cfrom :: forall x. CreateGame -> Rep CreateGame x
Prelude.Generic)

-- |
-- Create a value of 'CreateGame' 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', 'createGame_clientToken' - A client-defined token. With an active client token in the request, this
-- action is idempotent.
--
-- 'description', 'createGame_description' - The description of the game.
--
-- 'tags', 'createGame_tags' - The list of tags to apply to the game.
--
-- 'gameName', 'createGame_gameName' - The name of the game.
newCreateGame ::
  -- | 'gameName'
  Prelude.Text ->
  CreateGame
newCreateGame :: Text -> CreateGame
newCreateGame Text
pGameName_ =
  CreateGame'
    { $sel:clientToken:CreateGame' :: Maybe Text
clientToken = forall a. Maybe a
Prelude.Nothing,
      $sel:description:CreateGame' :: Maybe Text
description = forall a. Maybe a
Prelude.Nothing,
      $sel:tags:CreateGame' :: Maybe (HashMap Text Text)
tags = forall a. Maybe a
Prelude.Nothing,
      $sel:gameName:CreateGame' :: Text
gameName = Text
pGameName_
    }

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

-- | The description of the game.
createGame_description :: Lens.Lens' CreateGame (Prelude.Maybe Prelude.Text)
createGame_description :: Lens' CreateGame (Maybe Text)
createGame_description = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateGame' {Maybe Text
description :: Maybe Text
$sel:description:CreateGame' :: CreateGame -> Maybe Text
description} -> Maybe Text
description) (\s :: CreateGame
s@CreateGame' {} Maybe Text
a -> CreateGame
s {$sel:description:CreateGame' :: Maybe Text
description = Maybe Text
a} :: CreateGame)

-- | The list of tags to apply to the game.
createGame_tags :: Lens.Lens' CreateGame (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
createGame_tags :: Lens' CreateGame (Maybe (HashMap Text Text))
createGame_tags = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateGame' {Maybe (HashMap Text Text)
tags :: Maybe (HashMap Text Text)
$sel:tags:CreateGame' :: CreateGame -> Maybe (HashMap Text Text)
tags} -> Maybe (HashMap Text Text)
tags) (\s :: CreateGame
s@CreateGame' {} Maybe (HashMap Text Text)
a -> CreateGame
s {$sel:tags:CreateGame' :: Maybe (HashMap Text Text)
tags = Maybe (HashMap Text Text)
a} :: CreateGame) 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 name of the game.
createGame_gameName :: Lens.Lens' CreateGame Prelude.Text
createGame_gameName :: Lens' CreateGame Text
createGame_gameName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateGame' {Text
gameName :: Text
$sel:gameName:CreateGame' :: CreateGame -> Text
gameName} -> Text
gameName) (\s :: CreateGame
s@CreateGame' {} Text
a -> CreateGame
s {$sel:gameName:CreateGame' :: Text
gameName = Text
a} :: CreateGame)

instance Core.AWSRequest CreateGame where
  type AWSResponse CreateGame = CreateGameResponse
  request :: (Service -> Service) -> CreateGame -> Request CreateGame
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 CreateGame
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateGame)))
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 GameDetails -> Int -> CreateGameResponse
CreateGameResponse'
            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
"Game")
            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 CreateGame where
  hashWithSalt :: Int -> CreateGame -> Int
hashWithSalt Int
_salt CreateGame' {Maybe Text
Maybe (HashMap Text Text)
Text
gameName :: Text
tags :: Maybe (HashMap Text Text)
description :: Maybe Text
clientToken :: Maybe Text
$sel:gameName:CreateGame' :: CreateGame -> Text
$sel:tags:CreateGame' :: CreateGame -> Maybe (HashMap Text Text)
$sel:description:CreateGame' :: CreateGame -> Maybe Text
$sel:clientToken:CreateGame' :: CreateGame -> 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` Maybe Text
description
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text Text)
tags
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
gameName

instance Prelude.NFData CreateGame where
  rnf :: CreateGame -> ()
rnf CreateGame' {Maybe Text
Maybe (HashMap Text Text)
Text
gameName :: Text
tags :: Maybe (HashMap Text Text)
description :: Maybe Text
clientToken :: Maybe Text
$sel:gameName:CreateGame' :: CreateGame -> Text
$sel:tags:CreateGame' :: CreateGame -> Maybe (HashMap Text Text)
$sel:description:CreateGame' :: CreateGame -> Maybe Text
$sel:clientToken:CreateGame' :: CreateGame -> 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 Maybe Text
description
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text Text)
tags
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
gameName

instance Data.ToHeaders CreateGame where
  toHeaders :: CreateGame -> 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 CreateGame where
  toJSON :: CreateGame -> Value
toJSON CreateGame' {Maybe Text
Maybe (HashMap Text Text)
Text
gameName :: Text
tags :: Maybe (HashMap Text Text)
description :: Maybe Text
clientToken :: Maybe Text
$sel:gameName:CreateGame' :: CreateGame -> Text
$sel:tags:CreateGame' :: CreateGame -> Maybe (HashMap Text Text)
$sel:description:CreateGame' :: CreateGame -> Maybe Text
$sel:clientToken:CreateGame' :: CreateGame -> 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,
            (Key
"Description" 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
description,
            (Key
"Tags" 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 (HashMap Text Text)
tags,
            forall a. a -> Maybe a
Prelude.Just (Key
"GameName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
gameName)
          ]
      )

instance Data.ToPath CreateGame where
  toPath :: CreateGame -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/game"

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

-- | /See:/ 'newCreateGameResponse' smart constructor.
data CreateGameResponse = CreateGameResponse'
  { -- | Details about the game that was created.
    CreateGameResponse -> Maybe GameDetails
game :: Prelude.Maybe GameDetails,
    -- | The response's http status code.
    CreateGameResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CreateGameResponse -> CreateGameResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateGameResponse -> CreateGameResponse -> Bool
$c/= :: CreateGameResponse -> CreateGameResponse -> Bool
== :: CreateGameResponse -> CreateGameResponse -> Bool
$c== :: CreateGameResponse -> CreateGameResponse -> Bool
Prelude.Eq, ReadPrec [CreateGameResponse]
ReadPrec CreateGameResponse
Int -> ReadS CreateGameResponse
ReadS [CreateGameResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateGameResponse]
$creadListPrec :: ReadPrec [CreateGameResponse]
readPrec :: ReadPrec CreateGameResponse
$creadPrec :: ReadPrec CreateGameResponse
readList :: ReadS [CreateGameResponse]
$creadList :: ReadS [CreateGameResponse]
readsPrec :: Int -> ReadS CreateGameResponse
$creadsPrec :: Int -> ReadS CreateGameResponse
Prelude.Read, Int -> CreateGameResponse -> ShowS
[CreateGameResponse] -> ShowS
CreateGameResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateGameResponse] -> ShowS
$cshowList :: [CreateGameResponse] -> ShowS
show :: CreateGameResponse -> String
$cshow :: CreateGameResponse -> String
showsPrec :: Int -> CreateGameResponse -> ShowS
$cshowsPrec :: Int -> CreateGameResponse -> ShowS
Prelude.Show, forall x. Rep CreateGameResponse x -> CreateGameResponse
forall x. CreateGameResponse -> Rep CreateGameResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateGameResponse x -> CreateGameResponse
$cfrom :: forall x. CreateGameResponse -> Rep CreateGameResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateGameResponse' 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:
--
-- 'game', 'createGameResponse_game' - Details about the game that was created.
--
-- 'httpStatus', 'createGameResponse_httpStatus' - The response's http status code.
newCreateGameResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateGameResponse
newCreateGameResponse :: Int -> CreateGameResponse
newCreateGameResponse Int
pHttpStatus_ =
  CreateGameResponse'
    { $sel:game:CreateGameResponse' :: Maybe GameDetails
game = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateGameResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Details about the game that was created.
createGameResponse_game :: Lens.Lens' CreateGameResponse (Prelude.Maybe GameDetails)
createGameResponse_game :: Lens' CreateGameResponse (Maybe GameDetails)
createGameResponse_game = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateGameResponse' {Maybe GameDetails
game :: Maybe GameDetails
$sel:game:CreateGameResponse' :: CreateGameResponse -> Maybe GameDetails
game} -> Maybe GameDetails
game) (\s :: CreateGameResponse
s@CreateGameResponse' {} Maybe GameDetails
a -> CreateGameResponse
s {$sel:game:CreateGameResponse' :: Maybe GameDetails
game = Maybe GameDetails
a} :: CreateGameResponse)

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

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