{-# 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.SubscribeToShardEvent
-- 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.SubscribeToShardEvent 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.ChildShard
import Amazonka.Kinesis.Types.Record
import qualified Amazonka.Prelude as Prelude

-- | After you call SubscribeToShard, Kinesis Data Streams sends events of
-- this type over an HTTP\/2 connection to your consumer.
--
-- /See:/ 'newSubscribeToShardEvent' smart constructor.
data SubscribeToShardEvent = SubscribeToShardEvent'
  { -- | The list of the child shards of the current shard, returned only at the
    -- end of the current shard.
    SubscribeToShardEvent -> Maybe [ChildShard]
childShards :: Prelude.Maybe [ChildShard],
    SubscribeToShardEvent -> [Record]
records :: [Record],
    -- | Use this as @SequenceNumber@ in the next call to SubscribeToShard, with
    -- @StartingPosition@ set to @AT_SEQUENCE_NUMBER@ or
    -- @AFTER_SEQUENCE_NUMBER@. Use @ContinuationSequenceNumber@ for
    -- checkpointing because it captures your shard progress even when no data
    -- is written to the shard.
    SubscribeToShardEvent -> Text
continuationSequenceNumber :: Prelude.Text,
    -- | The number of milliseconds the read records are from the tip of the
    -- stream, indicating how far behind current time the consumer is. A value
    -- of zero indicates that record processing is caught up, and there are no
    -- new records to process at this moment.
    SubscribeToShardEvent -> Natural
millisBehindLatest :: Prelude.Natural
  }
  deriving (SubscribeToShardEvent -> SubscribeToShardEvent -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SubscribeToShardEvent -> SubscribeToShardEvent -> Bool
$c/= :: SubscribeToShardEvent -> SubscribeToShardEvent -> Bool
== :: SubscribeToShardEvent -> SubscribeToShardEvent -> Bool
$c== :: SubscribeToShardEvent -> SubscribeToShardEvent -> Bool
Prelude.Eq, ReadPrec [SubscribeToShardEvent]
ReadPrec SubscribeToShardEvent
Int -> ReadS SubscribeToShardEvent
ReadS [SubscribeToShardEvent]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SubscribeToShardEvent]
$creadListPrec :: ReadPrec [SubscribeToShardEvent]
readPrec :: ReadPrec SubscribeToShardEvent
$creadPrec :: ReadPrec SubscribeToShardEvent
readList :: ReadS [SubscribeToShardEvent]
$creadList :: ReadS [SubscribeToShardEvent]
readsPrec :: Int -> ReadS SubscribeToShardEvent
$creadsPrec :: Int -> ReadS SubscribeToShardEvent
Prelude.Read, Int -> SubscribeToShardEvent -> ShowS
[SubscribeToShardEvent] -> ShowS
SubscribeToShardEvent -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SubscribeToShardEvent] -> ShowS
$cshowList :: [SubscribeToShardEvent] -> ShowS
show :: SubscribeToShardEvent -> String
$cshow :: SubscribeToShardEvent -> String
showsPrec :: Int -> SubscribeToShardEvent -> ShowS
$cshowsPrec :: Int -> SubscribeToShardEvent -> ShowS
Prelude.Show, forall x. Rep SubscribeToShardEvent x -> SubscribeToShardEvent
forall x. SubscribeToShardEvent -> Rep SubscribeToShardEvent x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SubscribeToShardEvent x -> SubscribeToShardEvent
$cfrom :: forall x. SubscribeToShardEvent -> Rep SubscribeToShardEvent x
Prelude.Generic)

-- |
-- Create a value of 'SubscribeToShardEvent' 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:
--
-- 'childShards', 'subscribeToShardEvent_childShards' - The list of the child shards of the current shard, returned only at the
-- end of the current shard.
--
-- 'records', 'subscribeToShardEvent_records' -
--
-- 'continuationSequenceNumber', 'subscribeToShardEvent_continuationSequenceNumber' - Use this as @SequenceNumber@ in the next call to SubscribeToShard, with
-- @StartingPosition@ set to @AT_SEQUENCE_NUMBER@ or
-- @AFTER_SEQUENCE_NUMBER@. Use @ContinuationSequenceNumber@ for
-- checkpointing because it captures your shard progress even when no data
-- is written to the shard.
--
-- 'millisBehindLatest', 'subscribeToShardEvent_millisBehindLatest' - The number of milliseconds the read records are from the tip of the
-- stream, indicating how far behind current time the consumer is. A value
-- of zero indicates that record processing is caught up, and there are no
-- new records to process at this moment.
newSubscribeToShardEvent ::
  -- | 'continuationSequenceNumber'
  Prelude.Text ->
  -- | 'millisBehindLatest'
  Prelude.Natural ->
  SubscribeToShardEvent
newSubscribeToShardEvent :: Text -> Natural -> SubscribeToShardEvent
newSubscribeToShardEvent
  Text
pContinuationSequenceNumber_
  Natural
pMillisBehindLatest_ =
    SubscribeToShardEvent'
      { $sel:childShards:SubscribeToShardEvent' :: Maybe [ChildShard]
childShards =
          forall a. Maybe a
Prelude.Nothing,
        $sel:records:SubscribeToShardEvent' :: [Record]
records = forall a. Monoid a => a
Prelude.mempty,
        $sel:continuationSequenceNumber:SubscribeToShardEvent' :: Text
continuationSequenceNumber =
          Text
pContinuationSequenceNumber_,
        $sel:millisBehindLatest:SubscribeToShardEvent' :: Natural
millisBehindLatest = Natural
pMillisBehindLatest_
      }

-- | The list of the child shards of the current shard, returned only at the
-- end of the current shard.
subscribeToShardEvent_childShards :: Lens.Lens' SubscribeToShardEvent (Prelude.Maybe [ChildShard])
subscribeToShardEvent_childShards :: Lens' SubscribeToShardEvent (Maybe [ChildShard])
subscribeToShardEvent_childShards = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SubscribeToShardEvent' {Maybe [ChildShard]
childShards :: Maybe [ChildShard]
$sel:childShards:SubscribeToShardEvent' :: SubscribeToShardEvent -> Maybe [ChildShard]
childShards} -> Maybe [ChildShard]
childShards) (\s :: SubscribeToShardEvent
s@SubscribeToShardEvent' {} Maybe [ChildShard]
a -> SubscribeToShardEvent
s {$sel:childShards:SubscribeToShardEvent' :: Maybe [ChildShard]
childShards = Maybe [ChildShard]
a} :: SubscribeToShardEvent) 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

subscribeToShardEvent_records :: Lens.Lens' SubscribeToShardEvent [Record]
subscribeToShardEvent_records :: Lens' SubscribeToShardEvent [Record]
subscribeToShardEvent_records = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SubscribeToShardEvent' {[Record]
records :: [Record]
$sel:records:SubscribeToShardEvent' :: SubscribeToShardEvent -> [Record]
records} -> [Record]
records) (\s :: SubscribeToShardEvent
s@SubscribeToShardEvent' {} [Record]
a -> SubscribeToShardEvent
s {$sel:records:SubscribeToShardEvent' :: [Record]
records = [Record]
a} :: SubscribeToShardEvent) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Use this as @SequenceNumber@ in the next call to SubscribeToShard, with
-- @StartingPosition@ set to @AT_SEQUENCE_NUMBER@ or
-- @AFTER_SEQUENCE_NUMBER@. Use @ContinuationSequenceNumber@ for
-- checkpointing because it captures your shard progress even when no data
-- is written to the shard.
subscribeToShardEvent_continuationSequenceNumber :: Lens.Lens' SubscribeToShardEvent Prelude.Text
subscribeToShardEvent_continuationSequenceNumber :: Lens' SubscribeToShardEvent Text
subscribeToShardEvent_continuationSequenceNumber = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SubscribeToShardEvent' {Text
continuationSequenceNumber :: Text
$sel:continuationSequenceNumber:SubscribeToShardEvent' :: SubscribeToShardEvent -> Text
continuationSequenceNumber} -> Text
continuationSequenceNumber) (\s :: SubscribeToShardEvent
s@SubscribeToShardEvent' {} Text
a -> SubscribeToShardEvent
s {$sel:continuationSequenceNumber:SubscribeToShardEvent' :: Text
continuationSequenceNumber = Text
a} :: SubscribeToShardEvent)

-- | The number of milliseconds the read records are from the tip of the
-- stream, indicating how far behind current time the consumer is. A value
-- of zero indicates that record processing is caught up, and there are no
-- new records to process at this moment.
subscribeToShardEvent_millisBehindLatest :: Lens.Lens' SubscribeToShardEvent Prelude.Natural
subscribeToShardEvent_millisBehindLatest :: Lens' SubscribeToShardEvent Natural
subscribeToShardEvent_millisBehindLatest = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SubscribeToShardEvent' {Natural
millisBehindLatest :: Natural
$sel:millisBehindLatest:SubscribeToShardEvent' :: SubscribeToShardEvent -> Natural
millisBehindLatest} -> Natural
millisBehindLatest) (\s :: SubscribeToShardEvent
s@SubscribeToShardEvent' {} Natural
a -> SubscribeToShardEvent
s {$sel:millisBehindLatest:SubscribeToShardEvent' :: Natural
millisBehindLatest = Natural
a} :: SubscribeToShardEvent)

instance Data.FromJSON SubscribeToShardEvent where
  parseJSON :: Value -> Parser SubscribeToShardEvent
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"SubscribeToShardEvent"
      ( \Object
x ->
          Maybe [ChildShard]
-> [Record] -> Text -> Natural -> SubscribeToShardEvent
SubscribeToShardEvent'
            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
"ChildShards" 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
"Records" 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 a
Data..: Key
"ContinuationSequenceNumber")
            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
"MillisBehindLatest")
      )

instance Prelude.Hashable SubscribeToShardEvent where
  hashWithSalt :: Int -> SubscribeToShardEvent -> Int
hashWithSalt Int
_salt SubscribeToShardEvent' {Natural
[Record]
Maybe [ChildShard]
Text
millisBehindLatest :: Natural
continuationSequenceNumber :: Text
records :: [Record]
childShards :: Maybe [ChildShard]
$sel:millisBehindLatest:SubscribeToShardEvent' :: SubscribeToShardEvent -> Natural
$sel:continuationSequenceNumber:SubscribeToShardEvent' :: SubscribeToShardEvent -> Text
$sel:records:SubscribeToShardEvent' :: SubscribeToShardEvent -> [Record]
$sel:childShards:SubscribeToShardEvent' :: SubscribeToShardEvent -> Maybe [ChildShard]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [ChildShard]
childShards
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [Record]
records
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
continuationSequenceNumber
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Natural
millisBehindLatest

instance Prelude.NFData SubscribeToShardEvent where
  rnf :: SubscribeToShardEvent -> ()
rnf SubscribeToShardEvent' {Natural
[Record]
Maybe [ChildShard]
Text
millisBehindLatest :: Natural
continuationSequenceNumber :: Text
records :: [Record]
childShards :: Maybe [ChildShard]
$sel:millisBehindLatest:SubscribeToShardEvent' :: SubscribeToShardEvent -> Natural
$sel:continuationSequenceNumber:SubscribeToShardEvent' :: SubscribeToShardEvent -> Text
$sel:records:SubscribeToShardEvent' :: SubscribeToShardEvent -> [Record]
$sel:childShards:SubscribeToShardEvent' :: SubscribeToShardEvent -> Maybe [ChildShard]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [ChildShard]
childShards
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [Record]
records
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
continuationSequenceNumber
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Natural
millisBehindLatest