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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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 plaintext value contained in a @ValueHolder@ structure.
    ValueHolder -> Maybe Text
ionText :: Prelude.Maybe Prelude.Text,
    -- | An Amazon Ion binary value contained in a @ValueHolder@ structure.
    ValueHolder -> Maybe Base64
ionBinary :: Prelude.Maybe Core.Base64
  }
  deriving (ValueHolder -> ValueHolder -> Bool
(ValueHolder -> ValueHolder -> Bool)
-> (ValueHolder -> ValueHolder -> Bool) -> Eq ValueHolder
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]
(Int -> ReadS ValueHolder)
-> ReadS [ValueHolder]
-> ReadPrec ValueHolder
-> ReadPrec [ValueHolder]
-> Read 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
(Int -> ValueHolder -> ShowS)
-> (ValueHolder -> String)
-> ([ValueHolder] -> ShowS)
-> Show ValueHolder
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. ValueHolder -> Rep ValueHolder x)
-> (forall x. Rep ValueHolder x -> ValueHolder)
-> Generic ValueHolder
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:
--
-- 'ionText', 'valueHolder_ionText' - An Amazon Ion plaintext value contained in a @ValueHolder@ structure.
--
-- '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.
newValueHolder ::
  ValueHolder
newValueHolder :: ValueHolder
newValueHolder =
  ValueHolder' :: Maybe Text -> Maybe Base64 -> ValueHolder
ValueHolder'
    { $sel:ionText:ValueHolder' :: Maybe Text
ionText = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:ionBinary:ValueHolder' :: Maybe Base64
ionBinary = Maybe Base64
forall a. Maybe a
Prelude.Nothing
    }

-- | An Amazon Ion plaintext value contained in a @ValueHolder@ structure.
valueHolder_ionText :: Lens.Lens' ValueHolder (Prelude.Maybe Prelude.Text)
valueHolder_ionText :: (Maybe Text -> f (Maybe Text)) -> ValueHolder -> f ValueHolder
valueHolder_ionText = (ValueHolder -> Maybe Text)
-> (ValueHolder -> Maybe Text -> ValueHolder)
-> Lens ValueHolder ValueHolder (Maybe Text) (Maybe Text)
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)

-- | 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 :: (Maybe ByteString -> f (Maybe ByteString))
-> ValueHolder -> f ValueHolder
valueHolder_ionBinary = (ValueHolder -> Maybe Base64)
-> (ValueHolder -> Maybe Base64 -> ValueHolder)
-> Lens ValueHolder ValueHolder (Maybe Base64) (Maybe Base64)
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) ((Maybe Base64 -> f (Maybe Base64))
 -> ValueHolder -> f ValueHolder)
-> ((Maybe ByteString -> f (Maybe ByteString))
    -> Maybe Base64 -> f (Maybe Base64))
-> (Maybe ByteString -> f (Maybe ByteString))
-> ValueHolder
-> f ValueHolder
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

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

instance Prelude.Hashable ValueHolder

instance Prelude.NFData ValueHolder

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