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

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

-- | Set of key-value pairs that contain information about a game session.
-- When included in a game session request, these properties communicate
-- details to be used when setting up the new game session. For example, a
-- game property might specify a game mode, level, or map. Game properties
-- are passed to the game server process when initiating a new game
-- session. For more information, see the
-- <https://docs.aws.amazon.com/gamelift/latest/developerguide/gamelift-sdk-client-api.html#gamelift-sdk-client-api-create GameLift Developer Guide>.
--
-- /See:/ 'newGameProperty' smart constructor.
data GameProperty = GameProperty'
  { -- | The game property identifier.
    GameProperty -> Text
key :: Prelude.Text,
    -- | The game property value.
    GameProperty -> Text
value :: Prelude.Text
  }
  deriving (GameProperty -> GameProperty -> Bool
(GameProperty -> GameProperty -> Bool)
-> (GameProperty -> GameProperty -> Bool) -> Eq GameProperty
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GameProperty -> GameProperty -> Bool
$c/= :: GameProperty -> GameProperty -> Bool
== :: GameProperty -> GameProperty -> Bool
$c== :: GameProperty -> GameProperty -> Bool
Prelude.Eq, ReadPrec [GameProperty]
ReadPrec GameProperty
Int -> ReadS GameProperty
ReadS [GameProperty]
(Int -> ReadS GameProperty)
-> ReadS [GameProperty]
-> ReadPrec GameProperty
-> ReadPrec [GameProperty]
-> Read GameProperty
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GameProperty]
$creadListPrec :: ReadPrec [GameProperty]
readPrec :: ReadPrec GameProperty
$creadPrec :: ReadPrec GameProperty
readList :: ReadS [GameProperty]
$creadList :: ReadS [GameProperty]
readsPrec :: Int -> ReadS GameProperty
$creadsPrec :: Int -> ReadS GameProperty
Prelude.Read, Int -> GameProperty -> ShowS
[GameProperty] -> ShowS
GameProperty -> String
(Int -> GameProperty -> ShowS)
-> (GameProperty -> String)
-> ([GameProperty] -> ShowS)
-> Show GameProperty
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GameProperty] -> ShowS
$cshowList :: [GameProperty] -> ShowS
show :: GameProperty -> String
$cshow :: GameProperty -> String
showsPrec :: Int -> GameProperty -> ShowS
$cshowsPrec :: Int -> GameProperty -> ShowS
Prelude.Show, (forall x. GameProperty -> Rep GameProperty x)
-> (forall x. Rep GameProperty x -> GameProperty)
-> Generic GameProperty
forall x. Rep GameProperty x -> GameProperty
forall x. GameProperty -> Rep GameProperty x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GameProperty x -> GameProperty
$cfrom :: forall x. GameProperty -> Rep GameProperty x
Prelude.Generic)

-- |
-- Create a value of 'GameProperty' 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:
--
-- 'key', 'gameProperty_key' - The game property identifier.
--
-- 'value', 'gameProperty_value' - The game property value.
newGameProperty ::
  -- | 'key'
  Prelude.Text ->
  -- | 'value'
  Prelude.Text ->
  GameProperty
newGameProperty :: Text -> Text -> GameProperty
newGameProperty Text
pKey_ Text
pValue_ =
  GameProperty' :: Text -> Text -> GameProperty
GameProperty' {$sel:key:GameProperty' :: Text
key = Text
pKey_, $sel:value:GameProperty' :: Text
value = Text
pValue_}

-- | The game property identifier.
gameProperty_key :: Lens.Lens' GameProperty Prelude.Text
gameProperty_key :: (Text -> f Text) -> GameProperty -> f GameProperty
gameProperty_key = (GameProperty -> Text)
-> (GameProperty -> Text -> GameProperty)
-> Lens GameProperty GameProperty Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GameProperty' {Text
key :: Text
$sel:key:GameProperty' :: GameProperty -> Text
key} -> Text
key) (\s :: GameProperty
s@GameProperty' {} Text
a -> GameProperty
s {$sel:key:GameProperty' :: Text
key = Text
a} :: GameProperty)

-- | The game property value.
gameProperty_value :: Lens.Lens' GameProperty Prelude.Text
gameProperty_value :: (Text -> f Text) -> GameProperty -> f GameProperty
gameProperty_value = (GameProperty -> Text)
-> (GameProperty -> Text -> GameProperty)
-> Lens GameProperty GameProperty Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GameProperty' {Text
value :: Text
$sel:value:GameProperty' :: GameProperty -> Text
value} -> Text
value) (\s :: GameProperty
s@GameProperty' {} Text
a -> GameProperty
s {$sel:value:GameProperty' :: Text
value = Text
a} :: GameProperty)

instance Core.FromJSON GameProperty where
  parseJSON :: Value -> Parser GameProperty
parseJSON =
    String
-> (Object -> Parser GameProperty) -> Value -> Parser GameProperty
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"GameProperty"
      ( \Object
x ->
          Text -> Text -> GameProperty
GameProperty'
            (Text -> Text -> GameProperty)
-> Parser Text -> Parser (Text -> GameProperty)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Key") Parser (Text -> GameProperty) -> Parser Text -> Parser GameProperty
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Value")
      )

instance Prelude.Hashable GameProperty

instance Prelude.NFData GameProperty

instance Core.ToJSON GameProperty where
  toJSON :: GameProperty -> Value
toJSON GameProperty' {Text
value :: Text
key :: Text
$sel:value:GameProperty' :: GameProperty -> Text
$sel:key:GameProperty' :: GameProperty -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Key" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
key),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Value" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
value)
          ]
      )