{-# 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.QLDBSession.Types.ValueHolder
-- 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.QLDBSession.Types.ValueHolder 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

-- | A structure that can contain a value in multiple encoding formats.
--
-- /See:/ 'newValueHolder' smart constructor.
data ValueHolder = ValueHolder'
  { -- | An Amazon Ion binary value contained in a @ValueHolder@ structure.
    ValueHolder -> Maybe Base64
ionBinary :: Prelude.Maybe Data.Base64,
    -- | An Amazon Ion plaintext value contained in a @ValueHolder@ structure.
    ValueHolder -> Maybe Text
ionText :: Prelude.Maybe Prelude.Text
  }
  deriving (ValueHolder -> ValueHolder -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ValueHolder -> ValueHolder -> Bool
$c/= :: ValueHolder -> ValueHolder -> Bool
== :: ValueHolder -> ValueHolder -> Bool
$c== :: ValueHolder -> ValueHolder -> Bool
Prelude.Eq, ReadPrec [ValueHolder]
ReadPrec ValueHolder
Int -> ReadS ValueHolder
ReadS [ValueHolder]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ValueHolder]
$creadListPrec :: ReadPrec [ValueHolder]
readPrec :: ReadPrec ValueHolder
$creadPrec :: ReadPrec ValueHolder
readList :: ReadS [ValueHolder]
$creadList :: ReadS [ValueHolder]
readsPrec :: Int -> ReadS ValueHolder
$creadsPrec :: Int -> ReadS ValueHolder
Prelude.Read, Int -> ValueHolder -> ShowS
[ValueHolder] -> ShowS
ValueHolder -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ValueHolder] -> ShowS
$cshowList :: [ValueHolder] -> ShowS
show :: ValueHolder -> String
$cshow :: ValueHolder -> String
showsPrec :: Int -> ValueHolder -> ShowS
$cshowsPrec :: Int -> ValueHolder -> ShowS
Prelude.Show, forall x. Rep ValueHolder x -> ValueHolder
forall x. ValueHolder -> Rep ValueHolder x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ValueHolder x -> ValueHolder
$cfrom :: forall x. ValueHolder -> Rep ValueHolder x
Prelude.Generic)

-- |
-- Create a value of 'ValueHolder' 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:
--
-- 'ionBinary', 'valueHolder_ionBinary' - An Amazon Ion binary value contained in a @ValueHolder@ structure.--
-- -- /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.
--
-- 'ionText', 'valueHolder_ionText' - An Amazon Ion plaintext value contained in a @ValueHolder@ structure.
newValueHolder ::
  ValueHolder
newValueHolder :: ValueHolder
newValueHolder =
  ValueHolder'
    { $sel:ionBinary:ValueHolder' :: Maybe Base64
ionBinary = forall a. Maybe a
Prelude.Nothing,
      $sel:ionText:ValueHolder' :: Maybe Text
ionText = forall a. Maybe a
Prelude.Nothing
    }

-- | An Amazon Ion binary value contained in a @ValueHolder@ structure.--
-- -- /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.
valueHolder_ionBinary :: Lens.Lens' ValueHolder (Prelude.Maybe Prelude.ByteString)
valueHolder_ionBinary :: Lens' ValueHolder (Maybe ByteString)
valueHolder_ionBinary = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ValueHolder' {Maybe Base64
ionBinary :: Maybe Base64
$sel:ionBinary:ValueHolder' :: ValueHolder -> Maybe Base64
ionBinary} -> Maybe Base64
ionBinary) (\s :: ValueHolder
s@ValueHolder' {} Maybe Base64
a -> ValueHolder
s {$sel:ionBinary:ValueHolder' :: Maybe Base64
ionBinary = Maybe Base64
a} :: ValueHolder) 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

-- | An Amazon Ion plaintext value contained in a @ValueHolder@ structure.
valueHolder_ionText :: Lens.Lens' ValueHolder (Prelude.Maybe Prelude.Text)
valueHolder_ionText :: Lens' ValueHolder (Maybe Text)
valueHolder_ionText = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ValueHolder' {Maybe Text
ionText :: Maybe Text
$sel:ionText:ValueHolder' :: ValueHolder -> Maybe Text
ionText} -> Maybe Text
ionText) (\s :: ValueHolder
s@ValueHolder' {} Maybe Text
a -> ValueHolder
s {$sel:ionText:ValueHolder' :: Maybe Text
ionText = Maybe Text
a} :: ValueHolder)

instance Data.FromJSON ValueHolder where
  parseJSON :: Value -> Parser ValueHolder
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ValueHolder"
      ( \Object
x ->
          Maybe Base64 -> Maybe Text -> ValueHolder
ValueHolder'
            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
"IonBinary")
            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
"IonText")
      )

instance Prelude.Hashable ValueHolder where
  hashWithSalt :: Int -> ValueHolder -> Int
hashWithSalt Int
_salt ValueHolder' {Maybe Text
Maybe Base64
ionText :: Maybe Text
ionBinary :: Maybe Base64
$sel:ionText:ValueHolder' :: ValueHolder -> Maybe Text
$sel:ionBinary:ValueHolder' :: ValueHolder -> Maybe Base64
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Base64
ionBinary
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
ionText

instance Prelude.NFData ValueHolder where
  rnf :: ValueHolder -> ()
rnf ValueHolder' {Maybe Text
Maybe Base64
ionText :: Maybe Text
ionBinary :: Maybe Base64
$sel:ionText:ValueHolder' :: ValueHolder -> Maybe Text
$sel:ionBinary:ValueHolder' :: ValueHolder -> Maybe Base64
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Base64
ionBinary
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
ionText

instance Data.ToJSON ValueHolder where
  toJSON :: ValueHolder -> Value
toJSON ValueHolder' {Maybe Text
Maybe Base64
ionText :: Maybe Text
ionBinary :: Maybe Base64
$sel:ionText:ValueHolder' :: ValueHolder -> Maybe Text
$sel:ionBinary:ValueHolder' :: ValueHolder -> Maybe Base64
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"IonBinary" 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
ionBinary,
            (Key
"IonText" 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
ionText
          ]
      )