{-# 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.RDSData.Types.Field
-- 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.RDSData.Types.Field where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.RDSData.Types.ArrayValue

-- | Contains a value.
--
-- /See:/ 'newField' smart constructor.
data Field = Field'
  { -- | A value of double data type.
    Field -> Maybe Double
doubleValue :: Prelude.Maybe Prelude.Double,
    -- | A value of string data type.
    Field -> Maybe Text
stringValue :: Prelude.Maybe Prelude.Text,
    -- | A value of long data type.
    Field -> Maybe Integer
longValue :: Prelude.Maybe Prelude.Integer,
    -- | A value of Boolean data type.
    Field -> Maybe Bool
booleanValue :: Prelude.Maybe Prelude.Bool,
    -- | An array of values.
    Field -> Maybe ArrayValue
arrayValue :: Prelude.Maybe ArrayValue,
    -- | A value of BLOB data type.
    Field -> Maybe Base64
blobValue :: Prelude.Maybe Core.Base64,
    -- | A NULL value.
    Field -> Maybe Bool
isNull :: Prelude.Maybe Prelude.Bool
  }
  deriving (Field -> Field -> Bool
(Field -> Field -> Bool) -> (Field -> Field -> Bool) -> Eq Field
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Field -> Field -> Bool
$c/= :: Field -> Field -> Bool
== :: Field -> Field -> Bool
$c== :: Field -> Field -> Bool
Prelude.Eq, ReadPrec [Field]
ReadPrec Field
Int -> ReadS Field
ReadS [Field]
(Int -> ReadS Field)
-> ReadS [Field]
-> ReadPrec Field
-> ReadPrec [Field]
-> Read Field
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Field]
$creadListPrec :: ReadPrec [Field]
readPrec :: ReadPrec Field
$creadPrec :: ReadPrec Field
readList :: ReadS [Field]
$creadList :: ReadS [Field]
readsPrec :: Int -> ReadS Field
$creadsPrec :: Int -> ReadS Field
Prelude.Read, Int -> Field -> ShowS
[Field] -> ShowS
Field -> String
(Int -> Field -> ShowS)
-> (Field -> String) -> ([Field] -> ShowS) -> Show Field
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Field] -> ShowS
$cshowList :: [Field] -> ShowS
show :: Field -> String
$cshow :: Field -> String
showsPrec :: Int -> Field -> ShowS
$cshowsPrec :: Int -> Field -> ShowS
Prelude.Show, (forall x. Field -> Rep Field x)
-> (forall x. Rep Field x -> Field) -> Generic Field
forall x. Rep Field x -> Field
forall x. Field -> Rep Field x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Field x -> Field
$cfrom :: forall x. Field -> Rep Field x
Prelude.Generic)

-- |
-- Create a value of 'Field' 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:
--
-- 'doubleValue', 'field_doubleValue' - A value of double data type.
--
-- 'stringValue', 'field_stringValue' - A value of string data type.
--
-- 'longValue', 'field_longValue' - A value of long data type.
--
-- 'booleanValue', 'field_booleanValue' - A value of Boolean data type.
--
-- 'arrayValue', 'field_arrayValue' - An array of values.
--
-- 'blobValue', 'field_blobValue' - A value of BLOB data type.--
-- -- /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.
--
-- 'isNull', 'field_isNull' - A NULL value.
newField ::
  Field
newField :: Field
newField =
  Field' :: Maybe Double
-> Maybe Text
-> Maybe Integer
-> Maybe Bool
-> Maybe ArrayValue
-> Maybe Base64
-> Maybe Bool
-> Field
Field'
    { $sel:doubleValue:Field' :: Maybe Double
doubleValue = Maybe Double
forall a. Maybe a
Prelude.Nothing,
      $sel:stringValue:Field' :: Maybe Text
stringValue = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:longValue:Field' :: Maybe Integer
longValue = Maybe Integer
forall a. Maybe a
Prelude.Nothing,
      $sel:booleanValue:Field' :: Maybe Bool
booleanValue = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:arrayValue:Field' :: Maybe ArrayValue
arrayValue = Maybe ArrayValue
forall a. Maybe a
Prelude.Nothing,
      $sel:blobValue:Field' :: Maybe Base64
blobValue = Maybe Base64
forall a. Maybe a
Prelude.Nothing,
      $sel:isNull:Field' :: Maybe Bool
isNull = Maybe Bool
forall a. Maybe a
Prelude.Nothing
    }

-- | A value of double data type.
field_doubleValue :: Lens.Lens' Field (Prelude.Maybe Prelude.Double)
field_doubleValue :: (Maybe Double -> f (Maybe Double)) -> Field -> f Field
field_doubleValue = (Field -> Maybe Double)
-> (Field -> Maybe Double -> Field)
-> Lens Field Field (Maybe Double) (Maybe Double)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Field' {Maybe Double
doubleValue :: Maybe Double
$sel:doubleValue:Field' :: Field -> Maybe Double
doubleValue} -> Maybe Double
doubleValue) (\s :: Field
s@Field' {} Maybe Double
a -> Field
s {$sel:doubleValue:Field' :: Maybe Double
doubleValue = Maybe Double
a} :: Field)

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

-- | A value of long data type.
field_longValue :: Lens.Lens' Field (Prelude.Maybe Prelude.Integer)
field_longValue :: (Maybe Integer -> f (Maybe Integer)) -> Field -> f Field
field_longValue = (Field -> Maybe Integer)
-> (Field -> Maybe Integer -> Field)
-> Lens Field Field (Maybe Integer) (Maybe Integer)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Field' {Maybe Integer
longValue :: Maybe Integer
$sel:longValue:Field' :: Field -> Maybe Integer
longValue} -> Maybe Integer
longValue) (\s :: Field
s@Field' {} Maybe Integer
a -> Field
s {$sel:longValue:Field' :: Maybe Integer
longValue = Maybe Integer
a} :: Field)

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

-- | An array of values.
field_arrayValue :: Lens.Lens' Field (Prelude.Maybe ArrayValue)
field_arrayValue :: (Maybe ArrayValue -> f (Maybe ArrayValue)) -> Field -> f Field
field_arrayValue = (Field -> Maybe ArrayValue)
-> (Field -> Maybe ArrayValue -> Field)
-> Lens Field Field (Maybe ArrayValue) (Maybe ArrayValue)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Field' {Maybe ArrayValue
arrayValue :: Maybe ArrayValue
$sel:arrayValue:Field' :: Field -> Maybe ArrayValue
arrayValue} -> Maybe ArrayValue
arrayValue) (\s :: Field
s@Field' {} Maybe ArrayValue
a -> Field
s {$sel:arrayValue:Field' :: Maybe ArrayValue
arrayValue = Maybe ArrayValue
a} :: Field)

-- | A value of BLOB data type.--
-- -- /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.
field_blobValue :: Lens.Lens' Field (Prelude.Maybe Prelude.ByteString)
field_blobValue :: (Maybe ByteString -> f (Maybe ByteString)) -> Field -> f Field
field_blobValue = (Field -> Maybe Base64)
-> (Field -> Maybe Base64 -> Field)
-> Lens Field Field (Maybe Base64) (Maybe Base64)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Field' {Maybe Base64
blobValue :: Maybe Base64
$sel:blobValue:Field' :: Field -> Maybe Base64
blobValue} -> Maybe Base64
blobValue) (\s :: Field
s@Field' {} Maybe Base64
a -> Field
s {$sel:blobValue:Field' :: Maybe Base64
blobValue = Maybe Base64
a} :: Field) ((Maybe Base64 -> f (Maybe Base64)) -> Field -> f Field)
-> ((Maybe ByteString -> f (Maybe ByteString))
    -> Maybe Base64 -> f (Maybe Base64))
-> (Maybe ByteString -> f (Maybe ByteString))
-> Field
-> f Field
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 NULL value.
field_isNull :: Lens.Lens' Field (Prelude.Maybe Prelude.Bool)
field_isNull :: (Maybe Bool -> f (Maybe Bool)) -> Field -> f Field
field_isNull = (Field -> Maybe Bool)
-> (Field -> Maybe Bool -> Field)
-> Lens Field Field (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Field' {Maybe Bool
isNull :: Maybe Bool
$sel:isNull:Field' :: Field -> Maybe Bool
isNull} -> Maybe Bool
isNull) (\s :: Field
s@Field' {} Maybe Bool
a -> Field
s {$sel:isNull:Field' :: Maybe Bool
isNull = Maybe Bool
a} :: Field)

instance Core.FromJSON Field where
  parseJSON :: Value -> Parser Field
parseJSON =
    String -> (Object -> Parser Field) -> Value -> Parser Field
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Field"
      ( \Object
x ->
          Maybe Double
-> Maybe Text
-> Maybe Integer
-> Maybe Bool
-> Maybe ArrayValue
-> Maybe Base64
-> Maybe Bool
-> Field
Field'
            (Maybe Double
 -> Maybe Text
 -> Maybe Integer
 -> Maybe Bool
 -> Maybe ArrayValue
 -> Maybe Base64
 -> Maybe Bool
 -> Field)
-> Parser (Maybe Double)
-> Parser
     (Maybe Text
      -> Maybe Integer
      -> Maybe Bool
      -> Maybe ArrayValue
      -> Maybe Base64
      -> Maybe Bool
      -> Field)
forall (f :: * -> *) a b. Functor 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
"doubleValue")
            Parser
  (Maybe Text
   -> Maybe Integer
   -> Maybe Bool
   -> Maybe ArrayValue
   -> Maybe Base64
   -> Maybe Bool
   -> Field)
-> Parser (Maybe Text)
-> Parser
     (Maybe Integer
      -> Maybe Bool
      -> Maybe ArrayValue
      -> Maybe Base64
      -> Maybe Bool
      -> Field)
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 Integer
   -> Maybe Bool
   -> Maybe ArrayValue
   -> Maybe Base64
   -> Maybe Bool
   -> Field)
-> Parser (Maybe Integer)
-> Parser
     (Maybe Bool
      -> Maybe ArrayValue -> Maybe Base64 -> Maybe Bool -> Field)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Integer)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"longValue")
            Parser
  (Maybe Bool
   -> Maybe ArrayValue -> Maybe Base64 -> Maybe Bool -> Field)
-> Parser (Maybe Bool)
-> Parser (Maybe ArrayValue -> Maybe Base64 -> Maybe Bool -> Field)
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")
            Parser (Maybe ArrayValue -> Maybe Base64 -> Maybe Bool -> Field)
-> Parser (Maybe ArrayValue)
-> Parser (Maybe Base64 -> Maybe Bool -> Field)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe ArrayValue)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"arrayValue")
            Parser (Maybe Base64 -> Maybe Bool -> Field)
-> Parser (Maybe Base64) -> Parser (Maybe Bool -> Field)
forall (f :: * -> *) a b. Applicative f => 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
"blobValue")
            Parser (Maybe Bool -> Field) -> Parser (Maybe Bool) -> Parser Field
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
"isNull")
      )

instance Prelude.Hashable Field

instance Prelude.NFData Field

instance Core.ToJSON Field where
  toJSON :: Field -> Value
toJSON Field' {Maybe Bool
Maybe Double
Maybe Integer
Maybe Text
Maybe Base64
Maybe ArrayValue
isNull :: Maybe Bool
blobValue :: Maybe Base64
arrayValue :: Maybe ArrayValue
booleanValue :: Maybe Bool
longValue :: Maybe Integer
stringValue :: Maybe Text
doubleValue :: Maybe Double
$sel:isNull:Field' :: Field -> Maybe Bool
$sel:blobValue:Field' :: Field -> Maybe Base64
$sel:arrayValue:Field' :: Field -> Maybe ArrayValue
$sel:booleanValue:Field' :: Field -> Maybe Bool
$sel:longValue:Field' :: Field -> Maybe Integer
$sel:stringValue:Field' :: Field -> Maybe Text
$sel:doubleValue:Field' :: Field -> Maybe Double
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"doubleValue" 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
doubleValue,
            (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
"longValue" Text -> Integer -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Integer -> Pair) -> Maybe Integer -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Integer
longValue,
            (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,
            (Text
"arrayValue" Text -> ArrayValue -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (ArrayValue -> Pair) -> Maybe ArrayValue -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe ArrayValue
arrayValue,
            (Text
"blobValue" 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
blobValue,
            (Text
"isNull" 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
isNull
          ]
      )