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

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

-- | Values for use in Player attribute key-value pairs. This object lets you
-- specify an attribute value using any of the valid data types: string,
-- number, string array, or data map. Each @AttributeValue@ object can use
-- only one of the available properties.
--
-- /See:/ 'newAttributeValue' smart constructor.
data AttributeValue = AttributeValue'
  { -- | For a list of up to 10 strings. Maximum length for each string is 100
    -- characters. Duplicate values are not recognized; all occurrences of the
    -- repeated value after the first of a repeated value are ignored.
    AttributeValue -> Maybe [Text]
sl :: Prelude.Maybe [Prelude.Text],
    -- | For a map of up to 10 data type:value pairs. Maximum length for each
    -- string value is 100 characters.
    AttributeValue -> Maybe (HashMap Text Double)
sdm :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Double),
    -- | For number values, expressed as double.
    AttributeValue -> Maybe Double
n :: Prelude.Maybe Prelude.Double,
    -- | For single string values. Maximum string length is 100 characters.
    AttributeValue -> Maybe Text
s :: Prelude.Maybe Prelude.Text
  }
  deriving (AttributeValue -> AttributeValue -> Bool
(AttributeValue -> AttributeValue -> Bool)
-> (AttributeValue -> AttributeValue -> Bool) -> Eq AttributeValue
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AttributeValue -> AttributeValue -> Bool
$c/= :: AttributeValue -> AttributeValue -> Bool
== :: AttributeValue -> AttributeValue -> Bool
$c== :: AttributeValue -> AttributeValue -> Bool
Prelude.Eq, ReadPrec [AttributeValue]
ReadPrec AttributeValue
Int -> ReadS AttributeValue
ReadS [AttributeValue]
(Int -> ReadS AttributeValue)
-> ReadS [AttributeValue]
-> ReadPrec AttributeValue
-> ReadPrec [AttributeValue]
-> Read AttributeValue
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AttributeValue]
$creadListPrec :: ReadPrec [AttributeValue]
readPrec :: ReadPrec AttributeValue
$creadPrec :: ReadPrec AttributeValue
readList :: ReadS [AttributeValue]
$creadList :: ReadS [AttributeValue]
readsPrec :: Int -> ReadS AttributeValue
$creadsPrec :: Int -> ReadS AttributeValue
Prelude.Read, Int -> AttributeValue -> ShowS
[AttributeValue] -> ShowS
AttributeValue -> String
(Int -> AttributeValue -> ShowS)
-> (AttributeValue -> String)
-> ([AttributeValue] -> ShowS)
-> Show AttributeValue
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AttributeValue] -> ShowS
$cshowList :: [AttributeValue] -> ShowS
show :: AttributeValue -> String
$cshow :: AttributeValue -> String
showsPrec :: Int -> AttributeValue -> ShowS
$cshowsPrec :: Int -> AttributeValue -> ShowS
Prelude.Show, (forall x. AttributeValue -> Rep AttributeValue x)
-> (forall x. Rep AttributeValue x -> AttributeValue)
-> Generic AttributeValue
forall x. Rep AttributeValue x -> AttributeValue
forall x. AttributeValue -> Rep AttributeValue x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AttributeValue x -> AttributeValue
$cfrom :: forall x. AttributeValue -> Rep AttributeValue x
Prelude.Generic)

-- |
-- Create a value of 'AttributeValue' 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:
--
-- 'sl', 'attributeValue_sl' - For a list of up to 10 strings. Maximum length for each string is 100
-- characters. Duplicate values are not recognized; all occurrences of the
-- repeated value after the first of a repeated value are ignored.
--
-- 'sdm', 'attributeValue_sdm' - For a map of up to 10 data type:value pairs. Maximum length for each
-- string value is 100 characters.
--
-- 'n', 'attributeValue_n' - For number values, expressed as double.
--
-- 's', 'attributeValue_s' - For single string values. Maximum string length is 100 characters.
newAttributeValue ::
  AttributeValue
newAttributeValue :: AttributeValue
newAttributeValue =
  AttributeValue' :: Maybe [Text]
-> Maybe (HashMap Text Double)
-> Maybe Double
-> Maybe Text
-> AttributeValue
AttributeValue'
    { $sel:sl:AttributeValue' :: Maybe [Text]
sl = Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:sdm:AttributeValue' :: Maybe (HashMap Text Double)
sdm = Maybe (HashMap Text Double)
forall a. Maybe a
Prelude.Nothing,
      $sel:n:AttributeValue' :: Maybe Double
n = Maybe Double
forall a. Maybe a
Prelude.Nothing,
      $sel:s:AttributeValue' :: Maybe Text
s = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | For a list of up to 10 strings. Maximum length for each string is 100
-- characters. Duplicate values are not recognized; all occurrences of the
-- repeated value after the first of a repeated value are ignored.
attributeValue_sl :: Lens.Lens' AttributeValue (Prelude.Maybe [Prelude.Text])
attributeValue_sl :: (Maybe [Text] -> f (Maybe [Text]))
-> AttributeValue -> f AttributeValue
attributeValue_sl = (AttributeValue -> Maybe [Text])
-> (AttributeValue -> Maybe [Text] -> AttributeValue)
-> Lens AttributeValue AttributeValue (Maybe [Text]) (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttributeValue' {Maybe [Text]
sl :: Maybe [Text]
$sel:sl:AttributeValue' :: AttributeValue -> Maybe [Text]
sl} -> Maybe [Text]
sl) (\s :: AttributeValue
s@AttributeValue' {} Maybe [Text]
a -> AttributeValue
s {$sel:sl:AttributeValue' :: Maybe [Text]
sl = Maybe [Text]
a} :: AttributeValue) ((Maybe [Text] -> f (Maybe [Text]))
 -> AttributeValue -> f AttributeValue)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> AttributeValue
-> f AttributeValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [Text])
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 AnIso [Text] [Text] [Text] [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | For a map of up to 10 data type:value pairs. Maximum length for each
-- string value is 100 characters.
attributeValue_sdm :: Lens.Lens' AttributeValue (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Double))
attributeValue_sdm :: (Maybe (HashMap Text Double) -> f (Maybe (HashMap Text Double)))
-> AttributeValue -> f AttributeValue
attributeValue_sdm = (AttributeValue -> Maybe (HashMap Text Double))
-> (AttributeValue
    -> Maybe (HashMap Text Double) -> AttributeValue)
-> Lens
     AttributeValue
     AttributeValue
     (Maybe (HashMap Text Double))
     (Maybe (HashMap Text Double))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttributeValue' {Maybe (HashMap Text Double)
sdm :: Maybe (HashMap Text Double)
$sel:sdm:AttributeValue' :: AttributeValue -> Maybe (HashMap Text Double)
sdm} -> Maybe (HashMap Text Double)
sdm) (\s :: AttributeValue
s@AttributeValue' {} Maybe (HashMap Text Double)
a -> AttributeValue
s {$sel:sdm:AttributeValue' :: Maybe (HashMap Text Double)
sdm = Maybe (HashMap Text Double)
a} :: AttributeValue) ((Maybe (HashMap Text Double) -> f (Maybe (HashMap Text Double)))
 -> AttributeValue -> f AttributeValue)
-> ((Maybe (HashMap Text Double)
     -> f (Maybe (HashMap Text Double)))
    -> Maybe (HashMap Text Double) -> f (Maybe (HashMap Text Double)))
-> (Maybe (HashMap Text Double) -> f (Maybe (HashMap Text Double)))
-> AttributeValue
-> f AttributeValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text Double)
  (HashMap Text Double)
  (HashMap Text Double)
  (HashMap Text Double)
-> Iso
     (Maybe (HashMap Text Double))
     (Maybe (HashMap Text Double))
     (Maybe (HashMap Text Double))
     (Maybe (HashMap Text Double))
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 AnIso
  (HashMap Text Double)
  (HashMap Text Double)
  (HashMap Text Double)
  (HashMap Text Double)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | For number values, expressed as double.
attributeValue_n :: Lens.Lens' AttributeValue (Prelude.Maybe Prelude.Double)
attributeValue_n :: (Maybe Double -> f (Maybe Double))
-> AttributeValue -> f AttributeValue
attributeValue_n = (AttributeValue -> Maybe Double)
-> (AttributeValue -> Maybe Double -> AttributeValue)
-> Lens AttributeValue AttributeValue (Maybe Double) (Maybe Double)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttributeValue' {Maybe Double
n :: Maybe Double
$sel:n:AttributeValue' :: AttributeValue -> Maybe Double
n} -> Maybe Double
n) (\s :: AttributeValue
s@AttributeValue' {} Maybe Double
a -> AttributeValue
s {$sel:n:AttributeValue' :: Maybe Double
n = Maybe Double
a} :: AttributeValue)

-- | For single string values. Maximum string length is 100 characters.
attributeValue_s :: Lens.Lens' AttributeValue (Prelude.Maybe Prelude.Text)
attributeValue_s :: (Maybe Text -> f (Maybe Text))
-> AttributeValue -> f AttributeValue
attributeValue_s = (AttributeValue -> Maybe Text)
-> (AttributeValue -> Maybe Text -> AttributeValue)
-> Lens AttributeValue AttributeValue (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttributeValue' {Maybe Text
s :: Maybe Text
$sel:s:AttributeValue' :: AttributeValue -> Maybe Text
s} -> Maybe Text
s) (\s :: AttributeValue
s@AttributeValue' {} Maybe Text
a -> AttributeValue
s {$sel:s:AttributeValue' :: Maybe Text
s = Maybe Text
a} :: AttributeValue)

instance Core.FromJSON AttributeValue where
  parseJSON :: Value -> Parser AttributeValue
parseJSON =
    String
-> (Object -> Parser AttributeValue)
-> Value
-> Parser AttributeValue
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"AttributeValue"
      ( \Object
x ->
          Maybe [Text]
-> Maybe (HashMap Text Double)
-> Maybe Double
-> Maybe Text
-> AttributeValue
AttributeValue'
            (Maybe [Text]
 -> Maybe (HashMap Text Double)
 -> Maybe Double
 -> Maybe Text
 -> AttributeValue)
-> Parser (Maybe [Text])
-> Parser
     (Maybe (HashMap Text Double)
      -> Maybe Double -> Maybe Text -> AttributeValue)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe [Text]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"SL" Parser (Maybe (Maybe [Text]))
-> Maybe [Text] -> Parser (Maybe [Text])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [Text]
forall a. Monoid a => a
Prelude.mempty)
            Parser
  (Maybe (HashMap Text Double)
   -> Maybe Double -> Maybe Text -> AttributeValue)
-> Parser (Maybe (HashMap Text Double))
-> Parser (Maybe Double -> Maybe Text -> AttributeValue)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Maybe (HashMap Text Double)))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"SDM" Parser (Maybe (Maybe (HashMap Text Double)))
-> Maybe (HashMap Text Double)
-> Parser (Maybe (HashMap Text Double))
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe (HashMap Text Double)
forall a. Monoid a => a
Prelude.mempty)
            Parser (Maybe Double -> Maybe Text -> AttributeValue)
-> Parser (Maybe Double) -> Parser (Maybe Text -> AttributeValue)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"N")
            Parser (Maybe Text -> AttributeValue)
-> Parser (Maybe Text) -> Parser AttributeValue
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
"S")
      )

instance Prelude.Hashable AttributeValue

instance Prelude.NFData AttributeValue

instance Core.ToJSON AttributeValue where
  toJSON :: AttributeValue -> Value
toJSON AttributeValue' {Maybe Double
Maybe [Text]
Maybe Text
Maybe (HashMap Text Double)
s :: Maybe Text
n :: Maybe Double
sdm :: Maybe (HashMap Text Double)
sl :: Maybe [Text]
$sel:s:AttributeValue' :: AttributeValue -> Maybe Text
$sel:n:AttributeValue' :: AttributeValue -> Maybe Double
$sel:sdm:AttributeValue' :: AttributeValue -> Maybe (HashMap Text Double)
$sel:sl:AttributeValue' :: AttributeValue -> Maybe [Text]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"SL" 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]
sl,
            (Text
"SDM" Text -> HashMap Text Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (HashMap Text Double -> Pair)
-> Maybe (HashMap Text Double) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text Double)
sdm,
            (Text
"N" Text -> Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Double -> Pair) -> Maybe Double -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Double
n,
            (Text
"S" 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
s
          ]
      )