{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.Kinesis.Types.Record where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Kinesis.Types.EncryptionType
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 approximate time that the record was inserted into the stream.
    Record -> Maybe POSIX
approximateArrivalTimestamp :: Prelude.Maybe Data.POSIX,
    -- | 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 Amazon Web Services KMS key.
    Record -> Maybe EncryptionType
encryptionType :: Prelude.Maybe EncryptionType,
    -- | 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' :: Data.Base64,
    -- | Identifies which shard in the stream the data record is assigned to.
    Record -> Text
partitionKey :: Prelude.Text
  }
  deriving (Record -> Record -> Bool
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]
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
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. 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:
--
-- 'approximateArrivalTimestamp', 'record_approximateArrivalTimestamp' - The approximate time that the record was inserted into the stream.
--
-- '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 Amazon Web Services KMS key.
--
-- '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'
    { $sel:approximateArrivalTimestamp:Record' :: Maybe POSIX
approximateArrivalTimestamp =
        forall a. Maybe a
Prelude.Nothing,
      $sel:encryptionType:Record' :: Maybe EncryptionType
encryptionType = forall a. Maybe a
Prelude.Nothing,
      $sel:sequenceNumber:Record' :: Text
sequenceNumber = Text
pSequenceNumber_,
      $sel:data':Record' :: Base64
data' = Iso' Base64 ByteString
Data._Base64 forall t b. AReview t b -> b -> t
Lens.# ByteString
pData_,
      $sel:partitionKey:Record' :: Text
partitionKey = Text
pPartitionKey_
    }

-- | The approximate time that the record was inserted into the stream.
record_approximateArrivalTimestamp :: Lens.Lens' Record (Prelude.Maybe Prelude.UTCTime)
record_approximateArrivalTimestamp :: Lens' Record (Maybe UTCTime)
record_approximateArrivalTimestamp = 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) 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 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 Amazon Web Services KMS key.
record_encryptionType :: Lens.Lens' Record (Prelude.Maybe EncryptionType)
record_encryptionType :: Lens' Record (Maybe EncryptionType)
record_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 unique identifier of the record within its shard.
record_sequenceNumber :: Lens.Lens' Record Prelude.Text
record_sequenceNumber :: Lens' Record Text
record_sequenceNumber = 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 :: Lens' Record ByteString
record_data = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. Iso' Base64 ByteString
Data._Base64

-- | Identifies which shard in the stream the data record is assigned to.
record_partitionKey :: Lens.Lens' Record Prelude.Text
record_partitionKey :: Lens' Record Text
record_partitionKey = 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 Data.FromJSON Record where
  parseJSON :: Value -> Parser Record
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Record"
      ( \Object
x ->
          Maybe POSIX
-> Maybe EncryptionType -> Text -> Base64 -> Text -> Record
Record'
            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
"ApproximateArrivalTimestamp")
            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
"EncryptionType")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser 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 a
Data..: Key
"Data")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"PartitionKey")
      )

instance Prelude.Hashable Record where
  hashWithSalt :: Int -> Record -> Int
hashWithSalt Int
_salt Record' {Maybe POSIX
Maybe EncryptionType
Text
Base64
partitionKey :: Text
data' :: Base64
sequenceNumber :: Text
encryptionType :: Maybe EncryptionType
approximateArrivalTimestamp :: Maybe POSIX
$sel:partitionKey:Record' :: Record -> Text
$sel:data':Record' :: Record -> Base64
$sel:sequenceNumber:Record' :: Record -> Text
$sel:encryptionType:Record' :: Record -> Maybe EncryptionType
$sel:approximateArrivalTimestamp:Record' :: Record -> Maybe POSIX
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe POSIX
approximateArrivalTimestamp
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe EncryptionType
encryptionType
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
sequenceNumber
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Base64
data'
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
partitionKey

instance Prelude.NFData Record where
  rnf :: Record -> ()
rnf Record' {Maybe POSIX
Maybe EncryptionType
Text
Base64
partitionKey :: Text
data' :: Base64
sequenceNumber :: Text
encryptionType :: Maybe EncryptionType
approximateArrivalTimestamp :: Maybe POSIX
$sel:partitionKey:Record' :: Record -> Text
$sel:data':Record' :: Record -> Base64
$sel:sequenceNumber:Record' :: Record -> Text
$sel:encryptionType:Record' :: Record -> Maybe EncryptionType
$sel:approximateArrivalTimestamp:Record' :: Record -> Maybe POSIX
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe POSIX
approximateArrivalTimestamp
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe EncryptionType
encryptionType
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
sequenceNumber
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Base64
data'
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
partitionKey