{-# 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.DynamoDBStreams.Types.StreamRecord
-- 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.DynamoDBStreams.Types.StreamRecord where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.DynamoDBStreams.Internal
import Amazonka.DynamoDBStreams.Types.StreamViewType
import qualified Amazonka.Prelude as Prelude

-- | A description of a single data modification that was performed on an
-- item in a DynamoDB table.
--
-- /See:/ 'newStreamRecord' smart constructor.
data StreamRecord = StreamRecord'
  { -- | The approximate date and time when the stream record was created, in
    -- <http://www.epochconverter.com/ UNIX epoch time> format.
    StreamRecord -> Maybe POSIX
approximateCreationDateTime :: Prelude.Maybe Data.POSIX,
    -- | The primary key attribute(s) for the DynamoDB item that was modified.
    StreamRecord -> Maybe (HashMap Text AttributeValue)
keys :: Prelude.Maybe (Prelude.HashMap Prelude.Text AttributeValue),
    -- | The item in the DynamoDB table as it appeared after it was modified.
    StreamRecord -> Maybe (HashMap Text AttributeValue)
newImage' :: Prelude.Maybe (Prelude.HashMap Prelude.Text AttributeValue),
    -- | The item in the DynamoDB table as it appeared before it was modified.
    StreamRecord -> Maybe (HashMap Text AttributeValue)
oldImage :: Prelude.Maybe (Prelude.HashMap Prelude.Text AttributeValue),
    -- | The sequence number of the stream record.
    StreamRecord -> Maybe Text
sequenceNumber :: Prelude.Maybe Prelude.Text,
    -- | The size of the stream record, in bytes.
    StreamRecord -> Maybe Natural
sizeBytes :: Prelude.Maybe Prelude.Natural,
    -- | The type of data from the modified DynamoDB item that was captured in
    -- this stream record:
    --
    -- -   @KEYS_ONLY@ - only the key attributes of the modified item.
    --
    -- -   @NEW_IMAGE@ - the entire item, as it appeared after it was modified.
    --
    -- -   @OLD_IMAGE@ - the entire item, as it appeared before it was
    --     modified.
    --
    -- -   @NEW_AND_OLD_IMAGES@ - both the new and the old item images of the
    --     item.
    StreamRecord -> Maybe StreamViewType
streamViewType :: Prelude.Maybe StreamViewType
  }
  deriving (StreamRecord -> StreamRecord -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StreamRecord -> StreamRecord -> Bool
$c/= :: StreamRecord -> StreamRecord -> Bool
== :: StreamRecord -> StreamRecord -> Bool
$c== :: StreamRecord -> StreamRecord -> Bool
Prelude.Eq, ReadPrec [StreamRecord]
ReadPrec StreamRecord
Int -> ReadS StreamRecord
ReadS [StreamRecord]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StreamRecord]
$creadListPrec :: ReadPrec [StreamRecord]
readPrec :: ReadPrec StreamRecord
$creadPrec :: ReadPrec StreamRecord
readList :: ReadS [StreamRecord]
$creadList :: ReadS [StreamRecord]
readsPrec :: Int -> ReadS StreamRecord
$creadsPrec :: Int -> ReadS StreamRecord
Prelude.Read, Int -> StreamRecord -> ShowS
[StreamRecord] -> ShowS
StreamRecord -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StreamRecord] -> ShowS
$cshowList :: [StreamRecord] -> ShowS
show :: StreamRecord -> String
$cshow :: StreamRecord -> String
showsPrec :: Int -> StreamRecord -> ShowS
$cshowsPrec :: Int -> StreamRecord -> ShowS
Prelude.Show, forall x. Rep StreamRecord x -> StreamRecord
forall x. StreamRecord -> Rep StreamRecord x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StreamRecord x -> StreamRecord
$cfrom :: forall x. StreamRecord -> Rep StreamRecord x
Prelude.Generic)

-- |
-- Create a value of 'StreamRecord' 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:
--
-- 'approximateCreationDateTime', 'streamRecord_approximateCreationDateTime' - The approximate date and time when the stream record was created, in
-- <http://www.epochconverter.com/ UNIX epoch time> format.
--
-- 'keys', 'streamRecord_keys' - The primary key attribute(s) for the DynamoDB item that was modified.
--
-- 'newImage'', 'streamRecord_newImage' - The item in the DynamoDB table as it appeared after it was modified.
--
-- 'oldImage', 'streamRecord_oldImage' - The item in the DynamoDB table as it appeared before it was modified.
--
-- 'sequenceNumber', 'streamRecord_sequenceNumber' - The sequence number of the stream record.
--
-- 'sizeBytes', 'streamRecord_sizeBytes' - The size of the stream record, in bytes.
--
-- 'streamViewType', 'streamRecord_streamViewType' - The type of data from the modified DynamoDB item that was captured in
-- this stream record:
--
-- -   @KEYS_ONLY@ - only the key attributes of the modified item.
--
-- -   @NEW_IMAGE@ - the entire item, as it appeared after it was modified.
--
-- -   @OLD_IMAGE@ - the entire item, as it appeared before it was
--     modified.
--
-- -   @NEW_AND_OLD_IMAGES@ - both the new and the old item images of the
--     item.
newStreamRecord ::
  StreamRecord
newStreamRecord :: StreamRecord
newStreamRecord =
  StreamRecord'
    { $sel:approximateCreationDateTime:StreamRecord' :: Maybe POSIX
approximateCreationDateTime =
        forall a. Maybe a
Prelude.Nothing,
      $sel:keys:StreamRecord' :: Maybe (HashMap Text AttributeValue)
keys = forall a. Maybe a
Prelude.Nothing,
      $sel:newImage':StreamRecord' :: Maybe (HashMap Text AttributeValue)
newImage' = forall a. Maybe a
Prelude.Nothing,
      $sel:oldImage:StreamRecord' :: Maybe (HashMap Text AttributeValue)
oldImage = forall a. Maybe a
Prelude.Nothing,
      $sel:sequenceNumber:StreamRecord' :: Maybe Text
sequenceNumber = forall a. Maybe a
Prelude.Nothing,
      $sel:sizeBytes:StreamRecord' :: Maybe Natural
sizeBytes = forall a. Maybe a
Prelude.Nothing,
      $sel:streamViewType:StreamRecord' :: Maybe StreamViewType
streamViewType = forall a. Maybe a
Prelude.Nothing
    }

-- | The approximate date and time when the stream record was created, in
-- <http://www.epochconverter.com/ UNIX epoch time> format.
streamRecord_approximateCreationDateTime :: Lens.Lens' StreamRecord (Prelude.Maybe Prelude.UTCTime)
streamRecord_approximateCreationDateTime :: Lens' StreamRecord (Maybe UTCTime)
streamRecord_approximateCreationDateTime = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StreamRecord' {Maybe POSIX
approximateCreationDateTime :: Maybe POSIX
$sel:approximateCreationDateTime:StreamRecord' :: StreamRecord -> Maybe POSIX
approximateCreationDateTime} -> Maybe POSIX
approximateCreationDateTime) (\s :: StreamRecord
s@StreamRecord' {} Maybe POSIX
a -> StreamRecord
s {$sel:approximateCreationDateTime:StreamRecord' :: Maybe POSIX
approximateCreationDateTime = Maybe POSIX
a} :: StreamRecord) 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

-- | The primary key attribute(s) for the DynamoDB item that was modified.
streamRecord_keys :: Lens.Lens' StreamRecord (Prelude.Maybe (Prelude.HashMap Prelude.Text AttributeValue))
streamRecord_keys :: Lens' StreamRecord (Maybe (HashMap Text AttributeValue))
streamRecord_keys = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StreamRecord' {Maybe (HashMap Text AttributeValue)
keys :: Maybe (HashMap Text AttributeValue)
$sel:keys:StreamRecord' :: StreamRecord -> Maybe (HashMap Text AttributeValue)
keys} -> Maybe (HashMap Text AttributeValue)
keys) (\s :: StreamRecord
s@StreamRecord' {} Maybe (HashMap Text AttributeValue)
a -> StreamRecord
s {$sel:keys:StreamRecord' :: Maybe (HashMap Text AttributeValue)
keys = Maybe (HashMap Text AttributeValue)
a} :: StreamRecord) 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 s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The item in the DynamoDB table as it appeared after it was modified.
streamRecord_newImage :: Lens.Lens' StreamRecord (Prelude.Maybe (Prelude.HashMap Prelude.Text AttributeValue))
streamRecord_newImage :: Lens' StreamRecord (Maybe (HashMap Text AttributeValue))
streamRecord_newImage = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StreamRecord' {Maybe (HashMap Text AttributeValue)
newImage' :: Maybe (HashMap Text AttributeValue)
$sel:newImage':StreamRecord' :: StreamRecord -> Maybe (HashMap Text AttributeValue)
newImage'} -> Maybe (HashMap Text AttributeValue)
newImage') (\s :: StreamRecord
s@StreamRecord' {} Maybe (HashMap Text AttributeValue)
a -> StreamRecord
s {$sel:newImage':StreamRecord' :: Maybe (HashMap Text AttributeValue)
newImage' = Maybe (HashMap Text AttributeValue)
a} :: StreamRecord) 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 s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The item in the DynamoDB table as it appeared before it was modified.
streamRecord_oldImage :: Lens.Lens' StreamRecord (Prelude.Maybe (Prelude.HashMap Prelude.Text AttributeValue))
streamRecord_oldImage :: Lens' StreamRecord (Maybe (HashMap Text AttributeValue))
streamRecord_oldImage = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StreamRecord' {Maybe (HashMap Text AttributeValue)
oldImage :: Maybe (HashMap Text AttributeValue)
$sel:oldImage:StreamRecord' :: StreamRecord -> Maybe (HashMap Text AttributeValue)
oldImage} -> Maybe (HashMap Text AttributeValue)
oldImage) (\s :: StreamRecord
s@StreamRecord' {} Maybe (HashMap Text AttributeValue)
a -> StreamRecord
s {$sel:oldImage:StreamRecord' :: Maybe (HashMap Text AttributeValue)
oldImage = Maybe (HashMap Text AttributeValue)
a} :: StreamRecord) 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 s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The sequence number of the stream record.
streamRecord_sequenceNumber :: Lens.Lens' StreamRecord (Prelude.Maybe Prelude.Text)
streamRecord_sequenceNumber :: Lens' StreamRecord (Maybe Text)
streamRecord_sequenceNumber = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StreamRecord' {Maybe Text
sequenceNumber :: Maybe Text
$sel:sequenceNumber:StreamRecord' :: StreamRecord -> Maybe Text
sequenceNumber} -> Maybe Text
sequenceNumber) (\s :: StreamRecord
s@StreamRecord' {} Maybe Text
a -> StreamRecord
s {$sel:sequenceNumber:StreamRecord' :: Maybe Text
sequenceNumber = Maybe Text
a} :: StreamRecord)

-- | The size of the stream record, in bytes.
streamRecord_sizeBytes :: Lens.Lens' StreamRecord (Prelude.Maybe Prelude.Natural)
streamRecord_sizeBytes :: Lens' StreamRecord (Maybe Natural)
streamRecord_sizeBytes = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StreamRecord' {Maybe Natural
sizeBytes :: Maybe Natural
$sel:sizeBytes:StreamRecord' :: StreamRecord -> Maybe Natural
sizeBytes} -> Maybe Natural
sizeBytes) (\s :: StreamRecord
s@StreamRecord' {} Maybe Natural
a -> StreamRecord
s {$sel:sizeBytes:StreamRecord' :: Maybe Natural
sizeBytes = Maybe Natural
a} :: StreamRecord)

-- | The type of data from the modified DynamoDB item that was captured in
-- this stream record:
--
-- -   @KEYS_ONLY@ - only the key attributes of the modified item.
--
-- -   @NEW_IMAGE@ - the entire item, as it appeared after it was modified.
--
-- -   @OLD_IMAGE@ - the entire item, as it appeared before it was
--     modified.
--
-- -   @NEW_AND_OLD_IMAGES@ - both the new and the old item images of the
--     item.
streamRecord_streamViewType :: Lens.Lens' StreamRecord (Prelude.Maybe StreamViewType)
streamRecord_streamViewType :: Lens' StreamRecord (Maybe StreamViewType)
streamRecord_streamViewType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StreamRecord' {Maybe StreamViewType
streamViewType :: Maybe StreamViewType
$sel:streamViewType:StreamRecord' :: StreamRecord -> Maybe StreamViewType
streamViewType} -> Maybe StreamViewType
streamViewType) (\s :: StreamRecord
s@StreamRecord' {} Maybe StreamViewType
a -> StreamRecord
s {$sel:streamViewType:StreamRecord' :: Maybe StreamViewType
streamViewType = Maybe StreamViewType
a} :: StreamRecord)

instance Data.FromJSON StreamRecord where
  parseJSON :: Value -> Parser StreamRecord
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"StreamRecord"
      ( \Object
x ->
          Maybe POSIX
-> Maybe (HashMap Text AttributeValue)
-> Maybe (HashMap Text AttributeValue)
-> Maybe (HashMap Text AttributeValue)
-> Maybe Text
-> Maybe Natural
-> Maybe StreamViewType
-> StreamRecord
StreamRecord'
            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
"ApproximateCreationDateTime")
            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
"Keys" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            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
"NewImage" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            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
"OldImage" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            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
"SequenceNumber")
            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
"SizeBytes")
            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
"StreamViewType")
      )

instance Prelude.Hashable StreamRecord where
  hashWithSalt :: Int -> StreamRecord -> Int
hashWithSalt Int
_salt StreamRecord' {Maybe Natural
Maybe Text
Maybe (HashMap Text AttributeValue)
Maybe POSIX
Maybe StreamViewType
streamViewType :: Maybe StreamViewType
sizeBytes :: Maybe Natural
sequenceNumber :: Maybe Text
oldImage :: Maybe (HashMap Text AttributeValue)
newImage' :: Maybe (HashMap Text AttributeValue)
keys :: Maybe (HashMap Text AttributeValue)
approximateCreationDateTime :: Maybe POSIX
$sel:streamViewType:StreamRecord' :: StreamRecord -> Maybe StreamViewType
$sel:sizeBytes:StreamRecord' :: StreamRecord -> Maybe Natural
$sel:sequenceNumber:StreamRecord' :: StreamRecord -> Maybe Text
$sel:oldImage:StreamRecord' :: StreamRecord -> Maybe (HashMap Text AttributeValue)
$sel:newImage':StreamRecord' :: StreamRecord -> Maybe (HashMap Text AttributeValue)
$sel:keys:StreamRecord' :: StreamRecord -> Maybe (HashMap Text AttributeValue)
$sel:approximateCreationDateTime:StreamRecord' :: StreamRecord -> Maybe POSIX
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe POSIX
approximateCreationDateTime
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text AttributeValue)
keys
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text AttributeValue)
newImage'
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text AttributeValue)
oldImage
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
sequenceNumber
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
sizeBytes
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe StreamViewType
streamViewType

instance Prelude.NFData StreamRecord where
  rnf :: StreamRecord -> ()
rnf StreamRecord' {Maybe Natural
Maybe Text
Maybe (HashMap Text AttributeValue)
Maybe POSIX
Maybe StreamViewType
streamViewType :: Maybe StreamViewType
sizeBytes :: Maybe Natural
sequenceNumber :: Maybe Text
oldImage :: Maybe (HashMap Text AttributeValue)
newImage' :: Maybe (HashMap Text AttributeValue)
keys :: Maybe (HashMap Text AttributeValue)
approximateCreationDateTime :: Maybe POSIX
$sel:streamViewType:StreamRecord' :: StreamRecord -> Maybe StreamViewType
$sel:sizeBytes:StreamRecord' :: StreamRecord -> Maybe Natural
$sel:sequenceNumber:StreamRecord' :: StreamRecord -> Maybe Text
$sel:oldImage:StreamRecord' :: StreamRecord -> Maybe (HashMap Text AttributeValue)
$sel:newImage':StreamRecord' :: StreamRecord -> Maybe (HashMap Text AttributeValue)
$sel:keys:StreamRecord' :: StreamRecord -> Maybe (HashMap Text AttributeValue)
$sel:approximateCreationDateTime:StreamRecord' :: StreamRecord -> Maybe POSIX
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe POSIX
approximateCreationDateTime
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text AttributeValue)
keys
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text AttributeValue)
newImage'
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text AttributeValue)
oldImage
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
sequenceNumber
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
sizeBytes
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe StreamViewType
streamViewType