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

import qualified Amazonka.Core as Core
import Amazonka.Kinesis.Types.ChildShard
import Amazonka.Kinesis.Types.Record
import qualified Amazonka.Lens as Lens
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'
  { 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
(SubscribeToShardEvent -> SubscribeToShardEvent -> Bool)
-> (SubscribeToShardEvent -> SubscribeToShardEvent -> Bool)
-> Eq SubscribeToShardEvent
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]
(Int -> ReadS SubscribeToShardEvent)
-> ReadS [SubscribeToShardEvent]
-> ReadPrec SubscribeToShardEvent
-> ReadPrec [SubscribeToShardEvent]
-> Read 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
(Int -> SubscribeToShardEvent -> ShowS)
-> (SubscribeToShardEvent -> String)
-> ([SubscribeToShardEvent] -> ShowS)
-> Show SubscribeToShardEvent
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. SubscribeToShardEvent -> Rep SubscribeToShardEvent x)
-> (forall x. Rep SubscribeToShardEvent x -> SubscribeToShardEvent)
-> Generic SubscribeToShardEvent
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' - Undocumented member.
--
-- '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' :: Maybe [ChildShard]
-> [Record] -> Text -> Natural -> SubscribeToShardEvent
SubscribeToShardEvent'
      { $sel:childShards:SubscribeToShardEvent' :: Maybe [ChildShard]
childShards =
          Maybe [ChildShard]
forall a. Maybe a
Prelude.Nothing,
        $sel:records:SubscribeToShardEvent' :: [Record]
records = [Record]
forall a. Monoid a => a
Prelude.mempty,
        $sel:continuationSequenceNumber:SubscribeToShardEvent' :: Text
continuationSequenceNumber =
          Text
pContinuationSequenceNumber_,
        $sel:millisBehindLatest:SubscribeToShardEvent' :: Natural
millisBehindLatest = Natural
pMillisBehindLatest_
      }

-- | Undocumented member.
subscribeToShardEvent_childShards :: Lens.Lens' SubscribeToShardEvent (Prelude.Maybe [ChildShard])
subscribeToShardEvent_childShards :: (Maybe [ChildShard] -> f (Maybe [ChildShard]))
-> SubscribeToShardEvent -> f SubscribeToShardEvent
subscribeToShardEvent_childShards = (SubscribeToShardEvent -> Maybe [ChildShard])
-> (SubscribeToShardEvent
    -> Maybe [ChildShard] -> SubscribeToShardEvent)
-> Lens
     SubscribeToShardEvent
     SubscribeToShardEvent
     (Maybe [ChildShard])
     (Maybe [ChildShard])
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) ((Maybe [ChildShard] -> f (Maybe [ChildShard]))
 -> SubscribeToShardEvent -> f SubscribeToShardEvent)
-> ((Maybe [ChildShard] -> f (Maybe [ChildShard]))
    -> Maybe [ChildShard] -> f (Maybe [ChildShard]))
-> (Maybe [ChildShard] -> f (Maybe [ChildShard]))
-> SubscribeToShardEvent
-> f SubscribeToShardEvent
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [ChildShard] [ChildShard] [ChildShard] [ChildShard]
-> Iso
     (Maybe [ChildShard])
     (Maybe [ChildShard])
     (Maybe [ChildShard])
     (Maybe [ChildShard])
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 [ChildShard] [ChildShard] [ChildShard] [ChildShard]
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 :: ([Record] -> f [Record])
-> SubscribeToShardEvent -> f SubscribeToShardEvent
subscribeToShardEvent_records = (SubscribeToShardEvent -> [Record])
-> (SubscribeToShardEvent -> [Record] -> SubscribeToShardEvent)
-> Lens
     SubscribeToShardEvent SubscribeToShardEvent [Record] [Record]
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) (([Record] -> f [Record])
 -> SubscribeToShardEvent -> f SubscribeToShardEvent)
-> (([Record] -> f [Record]) -> [Record] -> f [Record])
-> ([Record] -> f [Record])
-> SubscribeToShardEvent
-> f SubscribeToShardEvent
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Record] -> f [Record]) -> [Record] -> f [Record]
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 :: (Text -> f Text)
-> SubscribeToShardEvent -> f SubscribeToShardEvent
subscribeToShardEvent_continuationSequenceNumber = (SubscribeToShardEvent -> Text)
-> (SubscribeToShardEvent -> Text -> SubscribeToShardEvent)
-> Lens SubscribeToShardEvent SubscribeToShardEvent Text Text
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 :: (Natural -> f Natural)
-> SubscribeToShardEvent -> f SubscribeToShardEvent
subscribeToShardEvent_millisBehindLatest = (SubscribeToShardEvent -> Natural)
-> (SubscribeToShardEvent -> Natural -> SubscribeToShardEvent)
-> Lens SubscribeToShardEvent SubscribeToShardEvent Natural Natural
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 Core.FromJSON SubscribeToShardEvent where
  parseJSON :: Value -> Parser SubscribeToShardEvent
parseJSON =
    String
-> (Object -> Parser SubscribeToShardEvent)
-> Value
-> Parser SubscribeToShardEvent
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"SubscribeToShardEvent"
      ( \Object
x ->
          Maybe [ChildShard]
-> [Record] -> Text -> Natural -> SubscribeToShardEvent
SubscribeToShardEvent'
            (Maybe [ChildShard]
 -> [Record] -> Text -> Natural -> SubscribeToShardEvent)
-> Parser (Maybe [ChildShard])
-> Parser ([Record] -> Text -> Natural -> SubscribeToShardEvent)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe [ChildShard]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ChildShards" Parser (Maybe (Maybe [ChildShard]))
-> Maybe [ChildShard] -> Parser (Maybe [ChildShard])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [ChildShard]
forall a. Monoid a => a
Prelude.mempty)
            Parser ([Record] -> Text -> Natural -> SubscribeToShardEvent)
-> Parser [Record]
-> Parser (Text -> Natural -> SubscribeToShardEvent)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe [Record])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Records" Parser (Maybe [Record]) -> [Record] -> Parser [Record]
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= [Record]
forall a. Monoid a => a
Prelude.mempty)
            Parser (Text -> Natural -> SubscribeToShardEvent)
-> Parser Text -> Parser (Natural -> SubscribeToShardEvent)
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
"ContinuationSequenceNumber")
            Parser (Natural -> SubscribeToShardEvent)
-> Parser Natural -> Parser SubscribeToShardEvent
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Natural
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"MillisBehindLatest")
      )

instance Prelude.Hashable SubscribeToShardEvent

instance Prelude.NFData SubscribeToShardEvent