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

import qualified Amazonka.Core as Core
import Amazonka.DynamoDBStreams.Types.Identity
import Amazonka.DynamoDBStreams.Types.OperationType
import Amazonka.DynamoDBStreams.Types.StreamRecord
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A description of a unique event within a stream.
--
-- /See:/ 'newRecord' smart constructor.
data Record = Record'
  { -- | Items that are deleted by the Time to Live process after expiration have
    -- the following fields:
    --
    -- -   Records[].userIdentity.type
    --
    --     \"Service\"
    --
    -- -   Records[].userIdentity.principalId
    --
    --     \"dynamodb.amazonaws.com\"
    Record -> Maybe Identity
userIdentity :: Prelude.Maybe Identity,
    -- | The version number of the stream record format. This number is updated
    -- whenever the structure of @Record@ is modified.
    --
    -- Client applications must not assume that @eventVersion@ will remain at a
    -- particular value, as this number is subject to change at any time. In
    -- general, @eventVersion@ will only increase as the low-level DynamoDB
    -- Streams API evolves.
    Record -> Maybe Text
eventVersion :: Prelude.Maybe Prelude.Text,
    -- | The main body of the stream record, containing all of the
    -- DynamoDB-specific fields.
    Record -> Maybe StreamRecord
dynamodb :: Prelude.Maybe StreamRecord,
    -- | The region in which the @GetRecords@ request was received.
    Record -> Maybe Text
awsRegion :: Prelude.Maybe Prelude.Text,
    -- | The type of data modification that was performed on the DynamoDB table:
    --
    -- -   @INSERT@ - a new item was added to the table.
    --
    -- -   @MODIFY@ - one or more of an existing item\'s attributes were
    --     modified.
    --
    -- -   @REMOVE@ - the item was deleted from the table
    Record -> Maybe OperationType
eventName :: Prelude.Maybe OperationType,
    -- | The AWS service from which the stream record originated. For DynamoDB
    -- Streams, this is @aws:dynamodb@.
    Record -> Maybe Text
eventSource :: Prelude.Maybe Prelude.Text,
    -- | A globally unique identifier for the event that was recorded in this
    -- stream record.
    Record -> Maybe Text
eventID :: Prelude.Maybe Prelude.Text
  }
  deriving (Record -> Record -> Bool
(Record -> Record -> Bool)
-> (Record -> Record -> Bool) -> Eq Record
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Record -> Record -> Bool
$c/= :: Record -> Record -> Bool
== :: Record -> Record -> Bool
$c== :: Record -> Record -> Bool
Prelude.Eq, ReadPrec [Record]
ReadPrec Record
Int -> ReadS Record
ReadS [Record]
(Int -> ReadS Record)
-> ReadS [Record]
-> ReadPrec Record
-> ReadPrec [Record]
-> Read Record
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Record]
$creadListPrec :: ReadPrec [Record]
readPrec :: ReadPrec Record
$creadPrec :: ReadPrec Record
readList :: ReadS [Record]
$creadList :: ReadS [Record]
readsPrec :: Int -> ReadS Record
$creadsPrec :: Int -> ReadS Record
Prelude.Read, Int -> Record -> ShowS
[Record] -> ShowS
Record -> String
(Int -> Record -> ShowS)
-> (Record -> String) -> ([Record] -> ShowS) -> Show Record
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Record] -> ShowS
$cshowList :: [Record] -> ShowS
show :: Record -> String
$cshow :: Record -> String
showsPrec :: Int -> Record -> ShowS
$cshowsPrec :: Int -> Record -> ShowS
Prelude.Show, (forall x. Record -> Rep Record x)
-> (forall x. Rep Record x -> Record) -> Generic Record
forall x. Rep Record x -> Record
forall x. Record -> Rep Record x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Record x -> Record
$cfrom :: forall x. Record -> Rep Record x
Prelude.Generic)

-- |
-- Create a value of 'Record' 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:
--
-- 'userIdentity', 'record_userIdentity' - Items that are deleted by the Time to Live process after expiration have
-- the following fields:
--
-- -   Records[].userIdentity.type
--
--     \"Service\"
--
-- -   Records[].userIdentity.principalId
--
--     \"dynamodb.amazonaws.com\"
--
-- 'eventVersion', 'record_eventVersion' - The version number of the stream record format. This number is updated
-- whenever the structure of @Record@ is modified.
--
-- Client applications must not assume that @eventVersion@ will remain at a
-- particular value, as this number is subject to change at any time. In
-- general, @eventVersion@ will only increase as the low-level DynamoDB
-- Streams API evolves.
--
-- 'dynamodb', 'record_dynamodb' - The main body of the stream record, containing all of the
-- DynamoDB-specific fields.
--
-- 'awsRegion', 'record_awsRegion' - The region in which the @GetRecords@ request was received.
--
-- 'eventName', 'record_eventName' - The type of data modification that was performed on the DynamoDB table:
--
-- -   @INSERT@ - a new item was added to the table.
--
-- -   @MODIFY@ - one or more of an existing item\'s attributes were
--     modified.
--
-- -   @REMOVE@ - the item was deleted from the table
--
-- 'eventSource', 'record_eventSource' - The AWS service from which the stream record originated. For DynamoDB
-- Streams, this is @aws:dynamodb@.
--
-- 'eventID', 'record_eventID' - A globally unique identifier for the event that was recorded in this
-- stream record.
newRecord ::
  Record
newRecord :: Record
newRecord =
  Record' :: Maybe Identity
-> Maybe Text
-> Maybe StreamRecord
-> Maybe Text
-> Maybe OperationType
-> Maybe Text
-> Maybe Text
-> Record
Record'
    { $sel:userIdentity:Record' :: Maybe Identity
userIdentity = Maybe Identity
forall a. Maybe a
Prelude.Nothing,
      $sel:eventVersion:Record' :: Maybe Text
eventVersion = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:dynamodb:Record' :: Maybe StreamRecord
dynamodb = Maybe StreamRecord
forall a. Maybe a
Prelude.Nothing,
      $sel:awsRegion:Record' :: Maybe Text
awsRegion = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:eventName:Record' :: Maybe OperationType
eventName = Maybe OperationType
forall a. Maybe a
Prelude.Nothing,
      $sel:eventSource:Record' :: Maybe Text
eventSource = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:eventID:Record' :: Maybe Text
eventID = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | Items that are deleted by the Time to Live process after expiration have
-- the following fields:
--
-- -   Records[].userIdentity.type
--
--     \"Service\"
--
-- -   Records[].userIdentity.principalId
--
--     \"dynamodb.amazonaws.com\"
record_userIdentity :: Lens.Lens' Record (Prelude.Maybe Identity)
record_userIdentity :: (Maybe Identity -> f (Maybe Identity)) -> Record -> f Record
record_userIdentity = (Record -> Maybe Identity)
-> (Record -> Maybe Identity -> Record)
-> Lens Record Record (Maybe Identity) (Maybe Identity)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Record' {Maybe Identity
userIdentity :: Maybe Identity
$sel:userIdentity:Record' :: Record -> Maybe Identity
userIdentity} -> Maybe Identity
userIdentity) (\s :: Record
s@Record' {} Maybe Identity
a -> Record
s {$sel:userIdentity:Record' :: Maybe Identity
userIdentity = Maybe Identity
a} :: Record)

-- | The version number of the stream record format. This number is updated
-- whenever the structure of @Record@ is modified.
--
-- Client applications must not assume that @eventVersion@ will remain at a
-- particular value, as this number is subject to change at any time. In
-- general, @eventVersion@ will only increase as the low-level DynamoDB
-- Streams API evolves.
record_eventVersion :: Lens.Lens' Record (Prelude.Maybe Prelude.Text)
record_eventVersion :: (Maybe Text -> f (Maybe Text)) -> Record -> f Record
record_eventVersion = (Record -> Maybe Text)
-> (Record -> Maybe Text -> Record)
-> Lens Record Record (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Record' {Maybe Text
eventVersion :: Maybe Text
$sel:eventVersion:Record' :: Record -> Maybe Text
eventVersion} -> Maybe Text
eventVersion) (\s :: Record
s@Record' {} Maybe Text
a -> Record
s {$sel:eventVersion:Record' :: Maybe Text
eventVersion = Maybe Text
a} :: Record)

-- | The main body of the stream record, containing all of the
-- DynamoDB-specific fields.
record_dynamodb :: Lens.Lens' Record (Prelude.Maybe StreamRecord)
record_dynamodb :: (Maybe StreamRecord -> f (Maybe StreamRecord))
-> Record -> f Record
record_dynamodb = (Record -> Maybe StreamRecord)
-> (Record -> Maybe StreamRecord -> Record)
-> Lens Record Record (Maybe StreamRecord) (Maybe StreamRecord)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Record' {Maybe StreamRecord
dynamodb :: Maybe StreamRecord
$sel:dynamodb:Record' :: Record -> Maybe StreamRecord
dynamodb} -> Maybe StreamRecord
dynamodb) (\s :: Record
s@Record' {} Maybe StreamRecord
a -> Record
s {$sel:dynamodb:Record' :: Maybe StreamRecord
dynamodb = Maybe StreamRecord
a} :: Record)

-- | The region in which the @GetRecords@ request was received.
record_awsRegion :: Lens.Lens' Record (Prelude.Maybe Prelude.Text)
record_awsRegion :: (Maybe Text -> f (Maybe Text)) -> Record -> f Record
record_awsRegion = (Record -> Maybe Text)
-> (Record -> Maybe Text -> Record)
-> Lens Record Record (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Record' {Maybe Text
awsRegion :: Maybe Text
$sel:awsRegion:Record' :: Record -> Maybe Text
awsRegion} -> Maybe Text
awsRegion) (\s :: Record
s@Record' {} Maybe Text
a -> Record
s {$sel:awsRegion:Record' :: Maybe Text
awsRegion = Maybe Text
a} :: Record)

-- | The type of data modification that was performed on the DynamoDB table:
--
-- -   @INSERT@ - a new item was added to the table.
--
-- -   @MODIFY@ - one or more of an existing item\'s attributes were
--     modified.
--
-- -   @REMOVE@ - the item was deleted from the table
record_eventName :: Lens.Lens' Record (Prelude.Maybe OperationType)
record_eventName :: (Maybe OperationType -> f (Maybe OperationType))
-> Record -> f Record
record_eventName = (Record -> Maybe OperationType)
-> (Record -> Maybe OperationType -> Record)
-> Lens Record Record (Maybe OperationType) (Maybe OperationType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Record' {Maybe OperationType
eventName :: Maybe OperationType
$sel:eventName:Record' :: Record -> Maybe OperationType
eventName} -> Maybe OperationType
eventName) (\s :: Record
s@Record' {} Maybe OperationType
a -> Record
s {$sel:eventName:Record' :: Maybe OperationType
eventName = Maybe OperationType
a} :: Record)

-- | The AWS service from which the stream record originated. For DynamoDB
-- Streams, this is @aws:dynamodb@.
record_eventSource :: Lens.Lens' Record (Prelude.Maybe Prelude.Text)
record_eventSource :: (Maybe Text -> f (Maybe Text)) -> Record -> f Record
record_eventSource = (Record -> Maybe Text)
-> (Record -> Maybe Text -> Record)
-> Lens Record Record (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Record' {Maybe Text
eventSource :: Maybe Text
$sel:eventSource:Record' :: Record -> Maybe Text
eventSource} -> Maybe Text
eventSource) (\s :: Record
s@Record' {} Maybe Text
a -> Record
s {$sel:eventSource:Record' :: Maybe Text
eventSource = Maybe Text
a} :: Record)

-- | A globally unique identifier for the event that was recorded in this
-- stream record.
record_eventID :: Lens.Lens' Record (Prelude.Maybe Prelude.Text)
record_eventID :: (Maybe Text -> f (Maybe Text)) -> Record -> f Record
record_eventID = (Record -> Maybe Text)
-> (Record -> Maybe Text -> Record)
-> Lens Record Record (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Record' {Maybe Text
eventID :: Maybe Text
$sel:eventID:Record' :: Record -> Maybe Text
eventID} -> Maybe Text
eventID) (\s :: Record
s@Record' {} Maybe Text
a -> Record
s {$sel:eventID:Record' :: Maybe Text
eventID = Maybe Text
a} :: Record)

instance Core.FromJSON Record where
  parseJSON :: Value -> Parser Record
parseJSON =
    String -> (Object -> Parser Record) -> Value -> Parser Record
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Record"
      ( \Object
x ->
          Maybe Identity
-> Maybe Text
-> Maybe StreamRecord
-> Maybe Text
-> Maybe OperationType
-> Maybe Text
-> Maybe Text
-> Record
Record'
            (Maybe Identity
 -> Maybe Text
 -> Maybe StreamRecord
 -> Maybe Text
 -> Maybe OperationType
 -> Maybe Text
 -> Maybe Text
 -> Record)
-> Parser (Maybe Identity)
-> Parser
     (Maybe Text
      -> Maybe StreamRecord
      -> Maybe Text
      -> Maybe OperationType
      -> Maybe Text
      -> Maybe Text
      -> Record)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Identity)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"userIdentity")
            Parser
  (Maybe Text
   -> Maybe StreamRecord
   -> Maybe Text
   -> Maybe OperationType
   -> Maybe Text
   -> Maybe Text
   -> Record)
-> Parser (Maybe Text)
-> Parser
     (Maybe StreamRecord
      -> Maybe Text
      -> Maybe OperationType
      -> Maybe Text
      -> Maybe Text
      -> Record)
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
"eventVersion")
            Parser
  (Maybe StreamRecord
   -> Maybe Text
   -> Maybe OperationType
   -> Maybe Text
   -> Maybe Text
   -> Record)
-> Parser (Maybe StreamRecord)
-> Parser
     (Maybe Text
      -> Maybe OperationType -> Maybe Text -> Maybe Text -> Record)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe StreamRecord)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"dynamodb")
            Parser
  (Maybe Text
   -> Maybe OperationType -> Maybe Text -> Maybe Text -> Record)
-> Parser (Maybe Text)
-> Parser
     (Maybe OperationType -> Maybe Text -> Maybe Text -> Record)
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
"awsRegion")
            Parser (Maybe OperationType -> Maybe Text -> Maybe Text -> Record)
-> Parser (Maybe OperationType)
-> Parser (Maybe Text -> Maybe Text -> Record)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe OperationType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"eventName")
            Parser (Maybe Text -> Maybe Text -> Record)
-> Parser (Maybe Text) -> Parser (Maybe Text -> Record)
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
"eventSource")
            Parser (Maybe Text -> Record)
-> Parser (Maybe Text) -> Parser Record
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
"eventID")
      )

instance Prelude.Hashable Record

instance Prelude.NFData Record