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

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

-- | For number values, expressed as double.
attributeValue_n :: Lens.Lens' AttributeValue (Prelude.Maybe Prelude.Double)
attributeValue_n :: Lens' AttributeValue (Maybe Double)
attributeValue_n = 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 :: Lens' AttributeValue (Maybe Text)
attributeValue_s = 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)

-- | 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 :: Lens' AttributeValue (Maybe (HashMap Text Double))
attributeValue_sdm = 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) 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

-- | For a list of up to 100 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 :: Lens' AttributeValue (Maybe [Text])
attributeValue_sl = 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) 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

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

instance Prelude.Hashable AttributeValue where
  hashWithSalt :: Int -> AttributeValue -> Int
hashWithSalt Int
_salt AttributeValue' {Maybe Double
Maybe [Text]
Maybe Text
Maybe (HashMap Text Double)
sl :: Maybe [Text]
sdm :: Maybe (HashMap Text Double)
s :: Maybe Text
n :: Maybe Double
$sel:sl:AttributeValue' :: AttributeValue -> Maybe [Text]
$sel:sdm:AttributeValue' :: AttributeValue -> Maybe (HashMap Text Double)
$sel:s:AttributeValue' :: AttributeValue -> Maybe Text
$sel:n:AttributeValue' :: AttributeValue -> Maybe Double
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Double
n
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
s
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text Double)
sdm
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Text]
sl

instance Prelude.NFData AttributeValue where
  rnf :: AttributeValue -> ()
rnf AttributeValue' {Maybe Double
Maybe [Text]
Maybe Text
Maybe (HashMap Text Double)
sl :: Maybe [Text]
sdm :: Maybe (HashMap Text Double)
s :: Maybe Text
n :: Maybe Double
$sel:sl:AttributeValue' :: AttributeValue -> Maybe [Text]
$sel:sdm:AttributeValue' :: AttributeValue -> Maybe (HashMap Text Double)
$sel:s:AttributeValue' :: AttributeValue -> Maybe Text
$sel:n:AttributeValue' :: AttributeValue -> Maybe Double
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Double
n
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
s
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text Double)
sdm
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
sl

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