{-# 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.PutRecordsRequestEntry
-- 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.PutRecordsRequestEntry where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Represents the output for @PutRecords@.
--
-- /See:/ 'newPutRecordsRequestEntry' smart constructor.
data PutRecordsRequestEntry = PutRecordsRequestEntry'
  { -- | The hash value used to determine explicitly the shard that the data
    -- record is assigned to by overriding the partition key hash.
    PutRecordsRequestEntry -> Maybe Text
explicitHashKey :: Prelude.Maybe Prelude.Text,
    -- | The data blob to put into the record, which is base64-encoded when the
    -- blob is serialized. 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).
    PutRecordsRequestEntry -> Base64
data' :: Core.Base64,
    -- | Determines which shard in the stream the data record is assigned to.
    -- Partition keys are Unicode strings with a maximum length limit of 256
    -- characters for each key. Amazon Kinesis Data Streams uses the partition
    -- key as input to a hash function that maps the partition key and
    -- associated data to a specific shard. Specifically, an MD5 hash function
    -- is used to map partition keys to 128-bit integer values and to map
    -- associated data records to shards. As a result of this hashing
    -- mechanism, all data records with the same partition key map to the same
    -- shard within the stream.
    PutRecordsRequestEntry -> Text
partitionKey :: Prelude.Text
  }
  deriving (PutRecordsRequestEntry -> PutRecordsRequestEntry -> Bool
(PutRecordsRequestEntry -> PutRecordsRequestEntry -> Bool)
-> (PutRecordsRequestEntry -> PutRecordsRequestEntry -> Bool)
-> Eq PutRecordsRequestEntry
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutRecordsRequestEntry -> PutRecordsRequestEntry -> Bool
$c/= :: PutRecordsRequestEntry -> PutRecordsRequestEntry -> Bool
== :: PutRecordsRequestEntry -> PutRecordsRequestEntry -> Bool
$c== :: PutRecordsRequestEntry -> PutRecordsRequestEntry -> Bool
Prelude.Eq, ReadPrec [PutRecordsRequestEntry]
ReadPrec PutRecordsRequestEntry
Int -> ReadS PutRecordsRequestEntry
ReadS [PutRecordsRequestEntry]
(Int -> ReadS PutRecordsRequestEntry)
-> ReadS [PutRecordsRequestEntry]
-> ReadPrec PutRecordsRequestEntry
-> ReadPrec [PutRecordsRequestEntry]
-> Read PutRecordsRequestEntry
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutRecordsRequestEntry]
$creadListPrec :: ReadPrec [PutRecordsRequestEntry]
readPrec :: ReadPrec PutRecordsRequestEntry
$creadPrec :: ReadPrec PutRecordsRequestEntry
readList :: ReadS [PutRecordsRequestEntry]
$creadList :: ReadS [PutRecordsRequestEntry]
readsPrec :: Int -> ReadS PutRecordsRequestEntry
$creadsPrec :: Int -> ReadS PutRecordsRequestEntry
Prelude.Read, Int -> PutRecordsRequestEntry -> ShowS
[PutRecordsRequestEntry] -> ShowS
PutRecordsRequestEntry -> String
(Int -> PutRecordsRequestEntry -> ShowS)
-> (PutRecordsRequestEntry -> String)
-> ([PutRecordsRequestEntry] -> ShowS)
-> Show PutRecordsRequestEntry
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutRecordsRequestEntry] -> ShowS
$cshowList :: [PutRecordsRequestEntry] -> ShowS
show :: PutRecordsRequestEntry -> String
$cshow :: PutRecordsRequestEntry -> String
showsPrec :: Int -> PutRecordsRequestEntry -> ShowS
$cshowsPrec :: Int -> PutRecordsRequestEntry -> ShowS
Prelude.Show, (forall x. PutRecordsRequestEntry -> Rep PutRecordsRequestEntry x)
-> (forall x.
    Rep PutRecordsRequestEntry x -> PutRecordsRequestEntry)
-> Generic PutRecordsRequestEntry
forall x. Rep PutRecordsRequestEntry x -> PutRecordsRequestEntry
forall x. PutRecordsRequestEntry -> Rep PutRecordsRequestEntry x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutRecordsRequestEntry x -> PutRecordsRequestEntry
$cfrom :: forall x. PutRecordsRequestEntry -> Rep PutRecordsRequestEntry x
Prelude.Generic)

-- |
-- Create a value of 'PutRecordsRequestEntry' 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:
--
-- 'explicitHashKey', 'putRecordsRequestEntry_explicitHashKey' - The hash value used to determine explicitly the shard that the data
-- record is assigned to by overriding the partition key hash.
--
-- 'data'', 'putRecordsRequestEntry_data' - The data blob to put into the record, which is base64-encoded when the
-- blob is serialized. 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', 'putRecordsRequestEntry_partitionKey' - Determines which shard in the stream the data record is assigned to.
-- Partition keys are Unicode strings with a maximum length limit of 256
-- characters for each key. Amazon Kinesis Data Streams uses the partition
-- key as input to a hash function that maps the partition key and
-- associated data to a specific shard. Specifically, an MD5 hash function
-- is used to map partition keys to 128-bit integer values and to map
-- associated data records to shards. As a result of this hashing
-- mechanism, all data records with the same partition key map to the same
-- shard within the stream.
newPutRecordsRequestEntry ::
  -- | 'data''
  Prelude.ByteString ->
  -- | 'partitionKey'
  Prelude.Text ->
  PutRecordsRequestEntry
newPutRecordsRequestEntry :: ByteString -> Text -> PutRecordsRequestEntry
newPutRecordsRequestEntry ByteString
pData_ Text
pPartitionKey_ =
  PutRecordsRequestEntry' :: Maybe Text -> Base64 -> Text -> PutRecordsRequestEntry
PutRecordsRequestEntry'
    { $sel:explicitHashKey:PutRecordsRequestEntry' :: Maybe Text
explicitHashKey =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:data':PutRecordsRequestEntry' :: 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:PutRecordsRequestEntry' :: Text
partitionKey = Text
pPartitionKey_
    }

-- | The hash value used to determine explicitly the shard that the data
-- record is assigned to by overriding the partition key hash.
putRecordsRequestEntry_explicitHashKey :: Lens.Lens' PutRecordsRequestEntry (Prelude.Maybe Prelude.Text)
putRecordsRequestEntry_explicitHashKey :: (Maybe Text -> f (Maybe Text))
-> PutRecordsRequestEntry -> f PutRecordsRequestEntry
putRecordsRequestEntry_explicitHashKey = (PutRecordsRequestEntry -> Maybe Text)
-> (PutRecordsRequestEntry -> Maybe Text -> PutRecordsRequestEntry)
-> Lens
     PutRecordsRequestEntry
     PutRecordsRequestEntry
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutRecordsRequestEntry' {Maybe Text
explicitHashKey :: Maybe Text
$sel:explicitHashKey:PutRecordsRequestEntry' :: PutRecordsRequestEntry -> Maybe Text
explicitHashKey} -> Maybe Text
explicitHashKey) (\s :: PutRecordsRequestEntry
s@PutRecordsRequestEntry' {} Maybe Text
a -> PutRecordsRequestEntry
s {$sel:explicitHashKey:PutRecordsRequestEntry' :: Maybe Text
explicitHashKey = Maybe Text
a} :: PutRecordsRequestEntry)

-- | The data blob to put into the record, which is base64-encoded when the
-- blob is serialized. 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.
putRecordsRequestEntry_data :: Lens.Lens' PutRecordsRequestEntry Prelude.ByteString
putRecordsRequestEntry_data :: (ByteString -> f ByteString)
-> PutRecordsRequestEntry -> f PutRecordsRequestEntry
putRecordsRequestEntry_data = (PutRecordsRequestEntry -> Base64)
-> (PutRecordsRequestEntry -> Base64 -> PutRecordsRequestEntry)
-> Lens PutRecordsRequestEntry PutRecordsRequestEntry Base64 Base64
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutRecordsRequestEntry' {Base64
data' :: Base64
$sel:data':PutRecordsRequestEntry' :: PutRecordsRequestEntry -> Base64
data'} -> Base64
data') (\s :: PutRecordsRequestEntry
s@PutRecordsRequestEntry' {} Base64
a -> PutRecordsRequestEntry
s {$sel:data':PutRecordsRequestEntry' :: Base64
data' = Base64
a} :: PutRecordsRequestEntry) ((Base64 -> f Base64)
 -> PutRecordsRequestEntry -> f PutRecordsRequestEntry)
-> ((ByteString -> f ByteString) -> Base64 -> f Base64)
-> (ByteString -> f ByteString)
-> PutRecordsRequestEntry
-> f PutRecordsRequestEntry
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (ByteString -> f ByteString) -> Base64 -> f Base64
Iso' Base64 ByteString
Core._Base64

-- | Determines which shard in the stream the data record is assigned to.
-- Partition keys are Unicode strings with a maximum length limit of 256
-- characters for each key. Amazon Kinesis Data Streams uses the partition
-- key as input to a hash function that maps the partition key and
-- associated data to a specific shard. Specifically, an MD5 hash function
-- is used to map partition keys to 128-bit integer values and to map
-- associated data records to shards. As a result of this hashing
-- mechanism, all data records with the same partition key map to the same
-- shard within the stream.
putRecordsRequestEntry_partitionKey :: Lens.Lens' PutRecordsRequestEntry Prelude.Text
putRecordsRequestEntry_partitionKey :: (Text -> f Text)
-> PutRecordsRequestEntry -> f PutRecordsRequestEntry
putRecordsRequestEntry_partitionKey = (PutRecordsRequestEntry -> Text)
-> (PutRecordsRequestEntry -> Text -> PutRecordsRequestEntry)
-> Lens PutRecordsRequestEntry PutRecordsRequestEntry Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutRecordsRequestEntry' {Text
partitionKey :: Text
$sel:partitionKey:PutRecordsRequestEntry' :: PutRecordsRequestEntry -> Text
partitionKey} -> Text
partitionKey) (\s :: PutRecordsRequestEntry
s@PutRecordsRequestEntry' {} Text
a -> PutRecordsRequestEntry
s {$sel:partitionKey:PutRecordsRequestEntry' :: Text
partitionKey = Text
a} :: PutRecordsRequestEntry)

instance Prelude.Hashable PutRecordsRequestEntry

instance Prelude.NFData PutRecordsRequestEntry

instance Core.ToJSON PutRecordsRequestEntry where
  toJSON :: PutRecordsRequestEntry -> Value
toJSON PutRecordsRequestEntry' {Maybe Text
Text
Base64
partitionKey :: Text
data' :: Base64
explicitHashKey :: Maybe Text
$sel:partitionKey:PutRecordsRequestEntry' :: PutRecordsRequestEntry -> Text
$sel:data':PutRecordsRequestEntry' :: PutRecordsRequestEntry -> Base64
$sel:explicitHashKey:PutRecordsRequestEntry' :: PutRecordsRequestEntry -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"ExplicitHashKey" 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
explicitHashKey,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Data" Text -> Base64 -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Base64
data'),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"PartitionKey" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
partitionKey)
          ]
      )