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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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 Core.Base64,
    -- | A date and time value.
    TypedAttributeValue -> Maybe POSIX
datetimeValue :: Prelude.Maybe Core.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,
    -- | A Boolean data value.
    TypedAttributeValue -> Maybe Bool
booleanValue :: Prelude.Maybe Prelude.Bool
  }
  deriving (TypedAttributeValue -> TypedAttributeValue -> Bool
(TypedAttributeValue -> TypedAttributeValue -> Bool)
-> (TypedAttributeValue -> TypedAttributeValue -> Bool)
-> Eq TypedAttributeValue
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]
(Int -> ReadS TypedAttributeValue)
-> ReadS [TypedAttributeValue]
-> ReadPrec TypedAttributeValue
-> ReadPrec [TypedAttributeValue]
-> Read 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
(Int -> TypedAttributeValue -> ShowS)
-> (TypedAttributeValue -> String)
-> ([TypedAttributeValue] -> ShowS)
-> Show TypedAttributeValue
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. TypedAttributeValue -> Rep TypedAttributeValue x)
-> (forall x. Rep TypedAttributeValue x -> TypedAttributeValue)
-> Generic TypedAttributeValue
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.
--
-- 'datetimeValue', 'typedAttributeValue_datetimeValue' - A date and time value.
--
-- 'numberValue', 'typedAttributeValue_numberValue' - A number data value.
--
-- 'stringValue', 'typedAttributeValue_stringValue' - A string data value.
--
-- 'booleanValue', 'typedAttributeValue_booleanValue' - A Boolean data value.
newTypedAttributeValue ::
  TypedAttributeValue
newTypedAttributeValue :: TypedAttributeValue
newTypedAttributeValue =
  TypedAttributeValue' :: Maybe Base64
-> Maybe POSIX
-> Maybe Text
-> Maybe Text
-> Maybe Bool
-> TypedAttributeValue
TypedAttributeValue'
    { $sel:binaryValue:TypedAttributeValue' :: Maybe Base64
binaryValue = Maybe Base64
forall a. Maybe a
Prelude.Nothing,
      $sel:datetimeValue:TypedAttributeValue' :: Maybe POSIX
datetimeValue = Maybe POSIX
forall a. Maybe a
Prelude.Nothing,
      $sel:numberValue:TypedAttributeValue' :: Maybe Text
numberValue = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:stringValue:TypedAttributeValue' :: Maybe Text
stringValue = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:booleanValue:TypedAttributeValue' :: Maybe Bool
booleanValue = Maybe Bool
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 :: (Maybe ByteString -> f (Maybe ByteString))
-> TypedAttributeValue -> f TypedAttributeValue
typedAttributeValue_binaryValue = (TypedAttributeValue -> Maybe Base64)
-> (TypedAttributeValue -> Maybe Base64 -> TypedAttributeValue)
-> Lens
     TypedAttributeValue
     TypedAttributeValue
     (Maybe Base64)
     (Maybe Base64)
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) ((Maybe Base64 -> f (Maybe Base64))
 -> TypedAttributeValue -> f TypedAttributeValue)
-> ((Maybe ByteString -> f (Maybe ByteString))
    -> Maybe Base64 -> f (Maybe Base64))
-> (Maybe ByteString -> f (Maybe ByteString))
-> TypedAttributeValue
-> f TypedAttributeValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso Base64 Base64 ByteString ByteString
-> Iso
     (Maybe Base64) (Maybe Base64) (Maybe ByteString) (Maybe ByteString)
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 Base64 Base64 ByteString ByteString
Iso' Base64 ByteString
Core._Base64

-- | A date and time value.
typedAttributeValue_datetimeValue :: Lens.Lens' TypedAttributeValue (Prelude.Maybe Prelude.UTCTime)
typedAttributeValue_datetimeValue :: (Maybe UTCTime -> f (Maybe UTCTime))
-> TypedAttributeValue -> f TypedAttributeValue
typedAttributeValue_datetimeValue = (TypedAttributeValue -> Maybe POSIX)
-> (TypedAttributeValue -> Maybe POSIX -> TypedAttributeValue)
-> Lens
     TypedAttributeValue TypedAttributeValue (Maybe POSIX) (Maybe POSIX)
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) ((Maybe POSIX -> f (Maybe POSIX))
 -> TypedAttributeValue -> f TypedAttributeValue)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> TypedAttributeValue
-> f TypedAttributeValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso POSIX POSIX UTCTime UTCTime
-> Iso (Maybe POSIX) (Maybe POSIX) (Maybe UTCTime) (Maybe UTCTime)
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 POSIX POSIX UTCTime UTCTime
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

-- | A number data value.
typedAttributeValue_numberValue :: Lens.Lens' TypedAttributeValue (Prelude.Maybe Prelude.Text)
typedAttributeValue_numberValue :: (Maybe Text -> f (Maybe Text))
-> TypedAttributeValue -> f TypedAttributeValue
typedAttributeValue_numberValue = (TypedAttributeValue -> Maybe Text)
-> (TypedAttributeValue -> Maybe Text -> TypedAttributeValue)
-> Lens
     TypedAttributeValue TypedAttributeValue (Maybe Text) (Maybe Text)
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 :: (Maybe Text -> f (Maybe Text))
-> TypedAttributeValue -> f TypedAttributeValue
typedAttributeValue_stringValue = (TypedAttributeValue -> Maybe Text)
-> (TypedAttributeValue -> Maybe Text -> TypedAttributeValue)
-> Lens
     TypedAttributeValue TypedAttributeValue (Maybe Text) (Maybe Text)
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)

-- | A Boolean data value.
typedAttributeValue_booleanValue :: Lens.Lens' TypedAttributeValue (Prelude.Maybe Prelude.Bool)
typedAttributeValue_booleanValue :: (Maybe Bool -> f (Maybe Bool))
-> TypedAttributeValue -> f TypedAttributeValue
typedAttributeValue_booleanValue = (TypedAttributeValue -> Maybe Bool)
-> (TypedAttributeValue -> Maybe Bool -> TypedAttributeValue)
-> Lens
     TypedAttributeValue TypedAttributeValue (Maybe Bool) (Maybe Bool)
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)

instance Core.FromJSON TypedAttributeValue where
  parseJSON :: Value -> Parser TypedAttributeValue
parseJSON =
    String
-> (Object -> Parser TypedAttributeValue)
-> Value
-> Parser TypedAttributeValue
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"TypedAttributeValue"
      ( \Object
x ->
          Maybe Base64
-> Maybe POSIX
-> Maybe Text
-> Maybe Text
-> Maybe Bool
-> TypedAttributeValue
TypedAttributeValue'
            (Maybe Base64
 -> Maybe POSIX
 -> Maybe Text
 -> Maybe Text
 -> Maybe Bool
 -> TypedAttributeValue)
-> Parser (Maybe Base64)
-> Parser
     (Maybe POSIX
      -> Maybe Text -> Maybe Text -> Maybe Bool -> TypedAttributeValue)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Base64)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"BinaryValue")
            Parser
  (Maybe POSIX
   -> Maybe Text -> Maybe Text -> Maybe Bool -> TypedAttributeValue)
-> Parser (Maybe POSIX)
-> Parser
     (Maybe Text -> Maybe Text -> Maybe Bool -> TypedAttributeValue)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe POSIX)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"DatetimeValue")
            Parser
  (Maybe Text -> Maybe Text -> Maybe Bool -> TypedAttributeValue)
-> Parser (Maybe Text)
-> Parser (Maybe Text -> Maybe Bool -> TypedAttributeValue)
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
"NumberValue")
            Parser (Maybe Text -> Maybe Bool -> TypedAttributeValue)
-> Parser (Maybe Text)
-> Parser (Maybe Bool -> TypedAttributeValue)
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
"StringValue")
            Parser (Maybe Bool -> TypedAttributeValue)
-> Parser (Maybe Bool) -> Parser TypedAttributeValue
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"BooleanValue")
      )

instance Prelude.Hashable TypedAttributeValue

instance Prelude.NFData TypedAttributeValue

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