{-# 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.CloudDirectory.Types.TypedAttributeValue
-- 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.CloudDirectory.Types.TypedAttributeValue 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

-- | Represents the data for a typed attribute. You can set one, and only
-- one, of the elements. Each attribute in an item is a name-value pair.
-- Attributes have a single value.
--
-- /See:/ 'newTypedAttributeValue' smart constructor.
data TypedAttributeValue = TypedAttributeValue'
  { -- | A binary data value.
    TypedAttributeValue -> Maybe Base64
binaryValue :: Prelude.Maybe Data.Base64,
    -- | A Boolean data value.
    TypedAttributeValue -> Maybe Bool
booleanValue :: Prelude.Maybe Prelude.Bool,
    -- | A date and time value.
    TypedAttributeValue -> Maybe POSIX
datetimeValue :: Prelude.Maybe Data.POSIX,
    -- | A number data value.
    TypedAttributeValue -> Maybe Text
numberValue :: Prelude.Maybe Prelude.Text,
    -- | A string data value.
    TypedAttributeValue -> Maybe Text
stringValue :: Prelude.Maybe Prelude.Text
  }
  deriving (TypedAttributeValue -> TypedAttributeValue -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TypedAttributeValue -> TypedAttributeValue -> Bool
$c/= :: TypedAttributeValue -> TypedAttributeValue -> Bool
== :: TypedAttributeValue -> TypedAttributeValue -> Bool
$c== :: TypedAttributeValue -> TypedAttributeValue -> Bool
Prelude.Eq, ReadPrec [TypedAttributeValue]
ReadPrec TypedAttributeValue
Int -> ReadS TypedAttributeValue
ReadS [TypedAttributeValue]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TypedAttributeValue]
$creadListPrec :: ReadPrec [TypedAttributeValue]
readPrec :: ReadPrec TypedAttributeValue
$creadPrec :: ReadPrec TypedAttributeValue
readList :: ReadS [TypedAttributeValue]
$creadList :: ReadS [TypedAttributeValue]
readsPrec :: Int -> ReadS TypedAttributeValue
$creadsPrec :: Int -> ReadS TypedAttributeValue
Prelude.Read, Int -> TypedAttributeValue -> ShowS
[TypedAttributeValue] -> ShowS
TypedAttributeValue -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TypedAttributeValue] -> ShowS
$cshowList :: [TypedAttributeValue] -> ShowS
show :: TypedAttributeValue -> String
$cshow :: TypedAttributeValue -> String
showsPrec :: Int -> TypedAttributeValue -> ShowS
$cshowsPrec :: Int -> TypedAttributeValue -> ShowS
Prelude.Show, forall x. Rep TypedAttributeValue x -> TypedAttributeValue
forall x. TypedAttributeValue -> Rep TypedAttributeValue x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TypedAttributeValue x -> TypedAttributeValue
$cfrom :: forall x. TypedAttributeValue -> Rep TypedAttributeValue x
Prelude.Generic)

-- |
-- Create a value of 'TypedAttributeValue' 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:
--
-- 'binaryValue', 'typedAttributeValue_binaryValue' - A binary data value.--
-- -- /Note:/ This 'Lens' automatically encodes and decodes Base64 data.
-- -- The underlying isomorphism will encode to Base64 representation during
-- -- serialisation, and decode from Base64 representation during deserialisation.
-- -- This 'Lens' accepts and returns only raw unencoded data.
--
-- 'booleanValue', 'typedAttributeValue_booleanValue' - A Boolean data value.
--
-- 'datetimeValue', 'typedAttributeValue_datetimeValue' - A date and time value.
--
-- 'numberValue', 'typedAttributeValue_numberValue' - A number data value.
--
-- 'stringValue', 'typedAttributeValue_stringValue' - A string data value.
newTypedAttributeValue ::
  TypedAttributeValue
newTypedAttributeValue :: TypedAttributeValue
newTypedAttributeValue =
  TypedAttributeValue'
    { $sel:binaryValue:TypedAttributeValue' :: Maybe Base64
binaryValue = forall a. Maybe a
Prelude.Nothing,
      $sel:booleanValue:TypedAttributeValue' :: Maybe Bool
booleanValue = forall a. Maybe a
Prelude.Nothing,
      $sel:datetimeValue:TypedAttributeValue' :: Maybe POSIX
datetimeValue = forall a. Maybe a
Prelude.Nothing,
      $sel:numberValue:TypedAttributeValue' :: Maybe Text
numberValue = forall a. Maybe a
Prelude.Nothing,
      $sel:stringValue:TypedAttributeValue' :: Maybe Text
stringValue = forall a. Maybe a
Prelude.Nothing
    }

-- | A binary data value.--
-- -- /Note:/ This 'Lens' automatically encodes and decodes Base64 data.
-- -- The underlying isomorphism will encode to Base64 representation during
-- -- serialisation, and decode from Base64 representation during deserialisation.
-- -- This 'Lens' accepts and returns only raw unencoded data.
typedAttributeValue_binaryValue :: Lens.Lens' TypedAttributeValue (Prelude.Maybe Prelude.ByteString)
typedAttributeValue_binaryValue :: Lens' TypedAttributeValue (Maybe ByteString)
typedAttributeValue_binaryValue = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TypedAttributeValue' {Maybe Base64
binaryValue :: Maybe Base64
$sel:binaryValue:TypedAttributeValue' :: TypedAttributeValue -> Maybe Base64
binaryValue} -> Maybe Base64
binaryValue) (\s :: TypedAttributeValue
s@TypedAttributeValue' {} Maybe Base64
a -> TypedAttributeValue
s {$sel:binaryValue:TypedAttributeValue' :: Maybe Base64
binaryValue = Maybe Base64
a} :: TypedAttributeValue) 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 Iso' Base64 ByteString
Data._Base64

-- | A Boolean data value.
typedAttributeValue_booleanValue :: Lens.Lens' TypedAttributeValue (Prelude.Maybe Prelude.Bool)
typedAttributeValue_booleanValue :: Lens' TypedAttributeValue (Maybe Bool)
typedAttributeValue_booleanValue = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TypedAttributeValue' {Maybe Bool
booleanValue :: Maybe Bool
$sel:booleanValue:TypedAttributeValue' :: TypedAttributeValue -> Maybe Bool
booleanValue} -> Maybe Bool
booleanValue) (\s :: TypedAttributeValue
s@TypedAttributeValue' {} Maybe Bool
a -> TypedAttributeValue
s {$sel:booleanValue:TypedAttributeValue' :: Maybe Bool
booleanValue = Maybe Bool
a} :: TypedAttributeValue)

-- | A date and time value.
typedAttributeValue_datetimeValue :: Lens.Lens' TypedAttributeValue (Prelude.Maybe Prelude.UTCTime)
typedAttributeValue_datetimeValue :: Lens' TypedAttributeValue (Maybe UTCTime)
typedAttributeValue_datetimeValue = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TypedAttributeValue' {Maybe POSIX
datetimeValue :: Maybe POSIX
$sel:datetimeValue:TypedAttributeValue' :: TypedAttributeValue -> Maybe POSIX
datetimeValue} -> Maybe POSIX
datetimeValue) (\s :: TypedAttributeValue
s@TypedAttributeValue' {} Maybe POSIX
a -> TypedAttributeValue
s {$sel:datetimeValue:TypedAttributeValue' :: Maybe POSIX
datetimeValue = Maybe POSIX
a} :: TypedAttributeValue) 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 (a :: Format). Iso' (Time a) UTCTime
Data._Time

-- | A number data value.
typedAttributeValue_numberValue :: Lens.Lens' TypedAttributeValue (Prelude.Maybe Prelude.Text)
typedAttributeValue_numberValue :: Lens' TypedAttributeValue (Maybe Text)
typedAttributeValue_numberValue = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TypedAttributeValue' {Maybe Text
numberValue :: Maybe Text
$sel:numberValue:TypedAttributeValue' :: TypedAttributeValue -> Maybe Text
numberValue} -> Maybe Text
numberValue) (\s :: TypedAttributeValue
s@TypedAttributeValue' {} Maybe Text
a -> TypedAttributeValue
s {$sel:numberValue:TypedAttributeValue' :: Maybe Text
numberValue = Maybe Text
a} :: TypedAttributeValue)

-- | A string data value.
typedAttributeValue_stringValue :: Lens.Lens' TypedAttributeValue (Prelude.Maybe Prelude.Text)
typedAttributeValue_stringValue :: Lens' TypedAttributeValue (Maybe Text)
typedAttributeValue_stringValue = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TypedAttributeValue' {Maybe Text
stringValue :: Maybe Text
$sel:stringValue:TypedAttributeValue' :: TypedAttributeValue -> Maybe Text
stringValue} -> Maybe Text
stringValue) (\s :: TypedAttributeValue
s@TypedAttributeValue' {} Maybe Text
a -> TypedAttributeValue
s {$sel:stringValue:TypedAttributeValue' :: Maybe Text
stringValue = Maybe Text
a} :: TypedAttributeValue)

instance Data.FromJSON TypedAttributeValue where
  parseJSON :: Value -> Parser TypedAttributeValue
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"TypedAttributeValue"
      ( \Object
x ->
          Maybe Base64
-> Maybe Bool
-> Maybe POSIX
-> Maybe Text
-> Maybe Text
-> TypedAttributeValue
TypedAttributeValue'
            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
"BinaryValue")
            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
"BooleanValue")
            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
"DatetimeValue")
            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
"NumberValue")
            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
"StringValue")
      )

instance Prelude.Hashable TypedAttributeValue where
  hashWithSalt :: Int -> TypedAttributeValue -> Int
hashWithSalt Int
_salt TypedAttributeValue' {Maybe Bool
Maybe Text
Maybe Base64
Maybe POSIX
stringValue :: Maybe Text
numberValue :: Maybe Text
datetimeValue :: Maybe POSIX
booleanValue :: Maybe Bool
binaryValue :: Maybe Base64
$sel:stringValue:TypedAttributeValue' :: TypedAttributeValue -> Maybe Text
$sel:numberValue:TypedAttributeValue' :: TypedAttributeValue -> Maybe Text
$sel:datetimeValue:TypedAttributeValue' :: TypedAttributeValue -> Maybe POSIX
$sel:booleanValue:TypedAttributeValue' :: TypedAttributeValue -> Maybe Bool
$sel:binaryValue:TypedAttributeValue' :: TypedAttributeValue -> Maybe Base64
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Base64
binaryValue
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
booleanValue
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe POSIX
datetimeValue
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
numberValue
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
stringValue

instance Prelude.NFData TypedAttributeValue where
  rnf :: TypedAttributeValue -> ()
rnf TypedAttributeValue' {Maybe Bool
Maybe Text
Maybe Base64
Maybe POSIX
stringValue :: Maybe Text
numberValue :: Maybe Text
datetimeValue :: Maybe POSIX
booleanValue :: Maybe Bool
binaryValue :: Maybe Base64
$sel:stringValue:TypedAttributeValue' :: TypedAttributeValue -> Maybe Text
$sel:numberValue:TypedAttributeValue' :: TypedAttributeValue -> Maybe Text
$sel:datetimeValue:TypedAttributeValue' :: TypedAttributeValue -> Maybe POSIX
$sel:booleanValue:TypedAttributeValue' :: TypedAttributeValue -> Maybe Bool
$sel:binaryValue:TypedAttributeValue' :: TypedAttributeValue -> Maybe Base64
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Base64
binaryValue
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
booleanValue
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe POSIX
datetimeValue
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
numberValue
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
stringValue

instance Data.ToJSON TypedAttributeValue where
  toJSON :: TypedAttributeValue -> Value
toJSON TypedAttributeValue' {Maybe Bool
Maybe Text
Maybe Base64
Maybe POSIX
stringValue :: Maybe Text
numberValue :: Maybe Text
datetimeValue :: Maybe POSIX
booleanValue :: Maybe Bool
binaryValue :: Maybe Base64
$sel:stringValue:TypedAttributeValue' :: TypedAttributeValue -> Maybe Text
$sel:numberValue:TypedAttributeValue' :: TypedAttributeValue -> Maybe Text
$sel:datetimeValue:TypedAttributeValue' :: TypedAttributeValue -> Maybe POSIX
$sel:booleanValue:TypedAttributeValue' :: TypedAttributeValue -> Maybe Bool
$sel:binaryValue:TypedAttributeValue' :: TypedAttributeValue -> Maybe Base64
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"BinaryValue" 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 Base64
binaryValue,
            (Key
"BooleanValue" 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 Bool
booleanValue,
            (Key
"DatetimeValue" 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 POSIX
datetimeValue,
            (Key
"NumberValue" 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
numberValue,
            (Key
"StringValue" 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
stringValue
          ]
      )