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

import qualified Amazonka.Core as Core
import Amazonka.Kinesis.Types.EncryptionType
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The unit of data of the Kinesis data stream, which is composed of a
-- sequence number, a partition key, and a data blob.
--
-- /See:/ 'newRecord' smart constructor.
data Record = Record'
  { -- | The encryption type used on the record. This parameter can be one of the
    -- following values:
    --
    -- -   @NONE@: Do not encrypt the records in the stream.
    --
    -- -   @KMS@: Use server-side encryption on the records in the stream using
    --     a customer-managed AWS KMS key.
    Record -> Maybe EncryptionType
encryptionType :: Prelude.Maybe EncryptionType,
    -- | The approximate time that the record was inserted into the stream.
    Record -> Maybe POSIX
approximateArrivalTimestamp :: Prelude.Maybe Core.POSIX,
    -- | The unique identifier of the record within its shard.
    Record -> Text
sequenceNumber :: Prelude.Text,
    -- | The data blob. The data in the blob is both opaque and immutable to
    -- Kinesis Data Streams, which does not inspect, interpret, or change the
    -- data in the blob in any way. When the data blob (the payload before
    -- base64-encoding) is added to the partition key size, the total size must
    -- not exceed the maximum record size (1 MiB).
    Record -> Base64
data' :: Core.Base64,
    -- | Identifies which shard in the stream the data record is assigned to.
    Record -> Text
partitionKey :: 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:
--
-- 'encryptionType', 'record_encryptionType' - The encryption type used on the record. This parameter can be one of the
-- following values:
--
-- -   @NONE@: Do not encrypt the records in the stream.
--
-- -   @KMS@: Use server-side encryption on the records in the stream using
--     a customer-managed AWS KMS key.
--
-- 'approximateArrivalTimestamp', 'record_approximateArrivalTimestamp' - The approximate time that the record was inserted into the stream.
--
-- 'sequenceNumber', 'record_sequenceNumber' - The unique identifier of the record within its shard.
--
-- 'data'', 'record_data' - The data blob. The data in the blob is both opaque and immutable to
-- Kinesis Data Streams, which does not inspect, interpret, or change the
-- data in the blob in any way. When the data blob (the payload before
-- base64-encoding) is added to the partition key size, the total size must
-- not exceed the maximum record size (1 MiB).--
-- -- /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.
--
-- 'partitionKey', 'record_partitionKey' - Identifies which shard in the stream the data record is assigned to.
newRecord ::
  -- | 'sequenceNumber'
  Prelude.Text ->
  -- | 'data''
  Prelude.ByteString ->
  -- | 'partitionKey'
  Prelude.Text ->
  Record
newRecord :: Text -> ByteString -> Text -> Record
newRecord Text
pSequenceNumber_ ByteString
pData_ Text
pPartitionKey_ =
  Record' :: Maybe EncryptionType
-> Maybe POSIX -> Text -> Base64 -> Text -> Record
Record'
    { $sel:encryptionType:Record' :: Maybe EncryptionType
encryptionType = Maybe EncryptionType
forall a. Maybe a
Prelude.Nothing,
      $sel:approximateArrivalTimestamp:Record' :: Maybe POSIX
approximateArrivalTimestamp = Maybe POSIX
forall a. Maybe a
Prelude.Nothing,
      $sel:sequenceNumber:Record' :: Text
sequenceNumber = Text
pSequenceNumber_,
      $sel:data':Record' :: Base64
data' = Tagged ByteString (Identity ByteString)
-> Tagged Base64 (Identity Base64)
Iso' Base64 ByteString
Core._Base64 (Tagged ByteString (Identity ByteString)
 -> Tagged Base64 (Identity Base64))
-> ByteString -> Base64
forall t b. AReview t b -> b -> t
Lens.# ByteString
pData_,
      $sel:partitionKey:Record' :: Text
partitionKey = Text
pPartitionKey_
    }

-- | The encryption type used on the record. This parameter can be one of the
-- following values:
--
-- -   @NONE@: Do not encrypt the records in the stream.
--
-- -   @KMS@: Use server-side encryption on the records in the stream using
--     a customer-managed AWS KMS key.
record_encryptionType :: Lens.Lens' Record (Prelude.Maybe EncryptionType)
record_encryptionType :: (Maybe EncryptionType -> f (Maybe EncryptionType))
-> Record -> f Record
record_encryptionType = (Record -> Maybe EncryptionType)
-> (Record -> Maybe EncryptionType -> Record)
-> Lens Record Record (Maybe EncryptionType) (Maybe EncryptionType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Record' {Maybe EncryptionType
encryptionType :: Maybe EncryptionType
$sel:encryptionType:Record' :: Record -> Maybe EncryptionType
encryptionType} -> Maybe EncryptionType
encryptionType) (\s :: Record
s@Record' {} Maybe EncryptionType
a -> Record
s {$sel:encryptionType:Record' :: Maybe EncryptionType
encryptionType = Maybe EncryptionType
a} :: Record)

-- | The approximate time that the record was inserted into the stream.
record_approximateArrivalTimestamp :: Lens.Lens' Record (Prelude.Maybe Prelude.UTCTime)
record_approximateArrivalTimestamp :: (Maybe UTCTime -> f (Maybe UTCTime)) -> Record -> f Record
record_approximateArrivalTimestamp = (Record -> Maybe POSIX)
-> (Record -> Maybe POSIX -> Record)
-> Lens Record Record (Maybe POSIX) (Maybe POSIX)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Record' {Maybe POSIX
approximateArrivalTimestamp :: Maybe POSIX
$sel:approximateArrivalTimestamp:Record' :: Record -> Maybe POSIX
approximateArrivalTimestamp} -> Maybe POSIX
approximateArrivalTimestamp) (\s :: Record
s@Record' {} Maybe POSIX
a -> Record
s {$sel:approximateArrivalTimestamp:Record' :: Maybe POSIX
approximateArrivalTimestamp = Maybe POSIX
a} :: Record) ((Maybe POSIX -> f (Maybe POSIX)) -> Record -> f Record)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> Record
-> f Record
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso POSIX POSIX UTCTime UTCTime
-> Iso (Maybe POSIX) (Maybe POSIX) (Maybe UTCTime) (Maybe UTCTime)
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 POSIX POSIX UTCTime UTCTime
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

-- | The unique identifier of the record within its shard.
record_sequenceNumber :: Lens.Lens' Record Prelude.Text
record_sequenceNumber :: (Text -> f Text) -> Record -> f Record
record_sequenceNumber = (Record -> Text)
-> (Record -> Text -> Record) -> Lens Record Record Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Record' {Text
sequenceNumber :: Text
$sel:sequenceNumber:Record' :: Record -> Text
sequenceNumber} -> Text
sequenceNumber) (\s :: Record
s@Record' {} Text
a -> Record
s {$sel:sequenceNumber:Record' :: Text
sequenceNumber = Text
a} :: Record)

-- | The data blob. The data in the blob is both opaque and immutable to
-- Kinesis Data Streams, which does not inspect, interpret, or change the
-- data in the blob in any way. When the data blob (the payload before
-- base64-encoding) is added to the partition key size, the total size must
-- not exceed the maximum record size (1 MiB).--
-- -- /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.
record_data :: Lens.Lens' Record Prelude.ByteString
record_data :: (ByteString -> f ByteString) -> Record -> f Record
record_data = (Record -> Base64)
-> (Record -> Base64 -> Record) -> Lens Record Record Base64 Base64
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Record' {Base64
data' :: Base64
$sel:data':Record' :: Record -> Base64
data'} -> Base64
data') (\s :: Record
s@Record' {} Base64
a -> Record
s {$sel:data':Record' :: Base64
data' = Base64
a} :: Record) ((Base64 -> f Base64) -> Record -> f Record)
-> ((ByteString -> f ByteString) -> Base64 -> f Base64)
-> (ByteString -> f ByteString)
-> Record
-> f Record
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (ByteString -> f ByteString) -> Base64 -> f Base64
Iso' Base64 ByteString
Core._Base64

-- | Identifies which shard in the stream the data record is assigned to.
record_partitionKey :: Lens.Lens' Record Prelude.Text
record_partitionKey :: (Text -> f Text) -> Record -> f Record
record_partitionKey = (Record -> Text)
-> (Record -> Text -> Record) -> Lens Record Record Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Record' {Text
partitionKey :: Text
$sel:partitionKey:Record' :: Record -> Text
partitionKey} -> Text
partitionKey) (\s :: Record
s@Record' {} Text
a -> Record
s {$sel:partitionKey:Record' :: Text
partitionKey = 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 EncryptionType
-> Maybe POSIX -> Text -> Base64 -> Text -> Record
Record'
            (Maybe EncryptionType
 -> Maybe POSIX -> Text -> Base64 -> Text -> Record)
-> Parser (Maybe EncryptionType)
-> Parser (Maybe POSIX -> Text -> Base64 -> Text -> Record)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe EncryptionType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"EncryptionType")
            Parser (Maybe POSIX -> Text -> Base64 -> Text -> Record)
-> Parser (Maybe POSIX)
-> Parser (Text -> Base64 -> Text -> Record)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe POSIX)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ApproximateArrivalTimestamp")
            Parser (Text -> Base64 -> Text -> Record)
-> Parser Text -> Parser (Base64 -> Text -> Record)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"SequenceNumber")
            Parser (Base64 -> Text -> Record)
-> Parser Base64 -> Parser (Text -> Record)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Base64
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Data")
            Parser (Text -> Record) -> Parser Text -> Parser Record
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"PartitionKey")
      )

instance Prelude.Hashable Record

instance Prelude.NFData Record