{-# 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.StartingPosition
-- 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.StartingPosition 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.ShardIteratorType
import qualified Amazonka.Prelude as Prelude

-- | The starting position in the data stream from which to start streaming.
--
-- /See:/ 'newStartingPosition' smart constructor.
data StartingPosition = StartingPosition'
  { -- | The sequence number of the data record in the shard from which to start
    -- streaming. To specify a sequence number, set @StartingPosition@ to
    -- @AT_SEQUENCE_NUMBER@ or @AFTER_SEQUENCE_NUMBER@.
    StartingPosition -> Maybe Text
sequenceNumber :: Prelude.Maybe Prelude.Text,
    -- | The time stamp of the data record from which to start reading. To
    -- specify a time stamp, set @StartingPosition@ to @Type AT_TIMESTAMP@. A
    -- time stamp is the Unix epoch date with precision in milliseconds. For
    -- example, @2016-04-04T19:58:46.480-00:00@ or @1459799926.480@. If a
    -- record with this exact time stamp does not exist, records will be
    -- streamed from the next (later) record. If the time stamp is older than
    -- the current trim horizon, records will be streamed from the oldest
    -- untrimmed data record (@TRIM_HORIZON@).
    StartingPosition -> Maybe POSIX
timestamp :: Prelude.Maybe Data.POSIX,
    -- | You can set the starting position to one of the following values:
    --
    -- @AT_SEQUENCE_NUMBER@: Start streaming from the position denoted by the
    -- sequence number specified in the @SequenceNumber@ field.
    --
    -- @AFTER_SEQUENCE_NUMBER@: Start streaming right after the position
    -- denoted by the sequence number specified in the @SequenceNumber@ field.
    --
    -- @AT_TIMESTAMP@: Start streaming from the position denoted by the time
    -- stamp specified in the @Timestamp@ field.
    --
    -- @TRIM_HORIZON@: Start streaming at the last untrimmed record in the
    -- shard, which is the oldest data record in the shard.
    --
    -- @LATEST@: Start streaming just after the most recent record in the
    -- shard, so that you always read the most recent data in the shard.
    StartingPosition -> ShardIteratorType
type' :: ShardIteratorType
  }
  deriving (StartingPosition -> StartingPosition -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StartingPosition -> StartingPosition -> Bool
$c/= :: StartingPosition -> StartingPosition -> Bool
== :: StartingPosition -> StartingPosition -> Bool
$c== :: StartingPosition -> StartingPosition -> Bool
Prelude.Eq, ReadPrec [StartingPosition]
ReadPrec StartingPosition
Int -> ReadS StartingPosition
ReadS [StartingPosition]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StartingPosition]
$creadListPrec :: ReadPrec [StartingPosition]
readPrec :: ReadPrec StartingPosition
$creadPrec :: ReadPrec StartingPosition
readList :: ReadS [StartingPosition]
$creadList :: ReadS [StartingPosition]
readsPrec :: Int -> ReadS StartingPosition
$creadsPrec :: Int -> ReadS StartingPosition
Prelude.Read, Int -> StartingPosition -> ShowS
[StartingPosition] -> ShowS
StartingPosition -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StartingPosition] -> ShowS
$cshowList :: [StartingPosition] -> ShowS
show :: StartingPosition -> String
$cshow :: StartingPosition -> String
showsPrec :: Int -> StartingPosition -> ShowS
$cshowsPrec :: Int -> StartingPosition -> ShowS
Prelude.Show, forall x. Rep StartingPosition x -> StartingPosition
forall x. StartingPosition -> Rep StartingPosition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StartingPosition x -> StartingPosition
$cfrom :: forall x. StartingPosition -> Rep StartingPosition x
Prelude.Generic)

-- |
-- Create a value of 'StartingPosition' 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:
--
-- 'sequenceNumber', 'startingPosition_sequenceNumber' - The sequence number of the data record in the shard from which to start
-- streaming. To specify a sequence number, set @StartingPosition@ to
-- @AT_SEQUENCE_NUMBER@ or @AFTER_SEQUENCE_NUMBER@.
--
-- 'timestamp', 'startingPosition_timestamp' - The time stamp of the data record from which to start reading. To
-- specify a time stamp, set @StartingPosition@ to @Type AT_TIMESTAMP@. A
-- time stamp is the Unix epoch date with precision in milliseconds. For
-- example, @2016-04-04T19:58:46.480-00:00@ or @1459799926.480@. If a
-- record with this exact time stamp does not exist, records will be
-- streamed from the next (later) record. If the time stamp is older than
-- the current trim horizon, records will be streamed from the oldest
-- untrimmed data record (@TRIM_HORIZON@).
--
-- 'type'', 'startingPosition_type' - You can set the starting position to one of the following values:
--
-- @AT_SEQUENCE_NUMBER@: Start streaming from the position denoted by the
-- sequence number specified in the @SequenceNumber@ field.
--
-- @AFTER_SEQUENCE_NUMBER@: Start streaming right after the position
-- denoted by the sequence number specified in the @SequenceNumber@ field.
--
-- @AT_TIMESTAMP@: Start streaming from the position denoted by the time
-- stamp specified in the @Timestamp@ field.
--
-- @TRIM_HORIZON@: Start streaming at the last untrimmed record in the
-- shard, which is the oldest data record in the shard.
--
-- @LATEST@: Start streaming just after the most recent record in the
-- shard, so that you always read the most recent data in the shard.
newStartingPosition ::
  -- | 'type''
  ShardIteratorType ->
  StartingPosition
newStartingPosition :: ShardIteratorType -> StartingPosition
newStartingPosition ShardIteratorType
pType_ =
  StartingPosition'
    { $sel:sequenceNumber:StartingPosition' :: Maybe Text
sequenceNumber = forall a. Maybe a
Prelude.Nothing,
      $sel:timestamp:StartingPosition' :: Maybe POSIX
timestamp = forall a. Maybe a
Prelude.Nothing,
      $sel:type':StartingPosition' :: ShardIteratorType
type' = ShardIteratorType
pType_
    }

-- | The sequence number of the data record in the shard from which to start
-- streaming. To specify a sequence number, set @StartingPosition@ to
-- @AT_SEQUENCE_NUMBER@ or @AFTER_SEQUENCE_NUMBER@.
startingPosition_sequenceNumber :: Lens.Lens' StartingPosition (Prelude.Maybe Prelude.Text)
startingPosition_sequenceNumber :: Lens' StartingPosition (Maybe Text)
startingPosition_sequenceNumber = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartingPosition' {Maybe Text
sequenceNumber :: Maybe Text
$sel:sequenceNumber:StartingPosition' :: StartingPosition -> Maybe Text
sequenceNumber} -> Maybe Text
sequenceNumber) (\s :: StartingPosition
s@StartingPosition' {} Maybe Text
a -> StartingPosition
s {$sel:sequenceNumber:StartingPosition' :: Maybe Text
sequenceNumber = Maybe Text
a} :: StartingPosition)

-- | The time stamp of the data record from which to start reading. To
-- specify a time stamp, set @StartingPosition@ to @Type AT_TIMESTAMP@. A
-- time stamp is the Unix epoch date with precision in milliseconds. For
-- example, @2016-04-04T19:58:46.480-00:00@ or @1459799926.480@. If a
-- record with this exact time stamp does not exist, records will be
-- streamed from the next (later) record. If the time stamp is older than
-- the current trim horizon, records will be streamed from the oldest
-- untrimmed data record (@TRIM_HORIZON@).
startingPosition_timestamp :: Lens.Lens' StartingPosition (Prelude.Maybe Prelude.UTCTime)
startingPosition_timestamp :: Lens' StartingPosition (Maybe UTCTime)
startingPosition_timestamp = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartingPosition' {Maybe POSIX
timestamp :: Maybe POSIX
$sel:timestamp:StartingPosition' :: StartingPosition -> Maybe POSIX
timestamp} -> Maybe POSIX
timestamp) (\s :: StartingPosition
s@StartingPosition' {} Maybe POSIX
a -> StartingPosition
s {$sel:timestamp:StartingPosition' :: Maybe POSIX
timestamp = Maybe POSIX
a} :: StartingPosition) 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

-- | You can set the starting position to one of the following values:
--
-- @AT_SEQUENCE_NUMBER@: Start streaming from the position denoted by the
-- sequence number specified in the @SequenceNumber@ field.
--
-- @AFTER_SEQUENCE_NUMBER@: Start streaming right after the position
-- denoted by the sequence number specified in the @SequenceNumber@ field.
--
-- @AT_TIMESTAMP@: Start streaming from the position denoted by the time
-- stamp specified in the @Timestamp@ field.
--
-- @TRIM_HORIZON@: Start streaming at the last untrimmed record in the
-- shard, which is the oldest data record in the shard.
--
-- @LATEST@: Start streaming just after the most recent record in the
-- shard, so that you always read the most recent data in the shard.
startingPosition_type :: Lens.Lens' StartingPosition ShardIteratorType
startingPosition_type :: Lens' StartingPosition ShardIteratorType
startingPosition_type = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartingPosition' {ShardIteratorType
type' :: ShardIteratorType
$sel:type':StartingPosition' :: StartingPosition -> ShardIteratorType
type'} -> ShardIteratorType
type') (\s :: StartingPosition
s@StartingPosition' {} ShardIteratorType
a -> StartingPosition
s {$sel:type':StartingPosition' :: ShardIteratorType
type' = ShardIteratorType
a} :: StartingPosition)

instance Prelude.Hashable StartingPosition where
  hashWithSalt :: Int -> StartingPosition -> Int
hashWithSalt Int
_salt StartingPosition' {Maybe Text
Maybe POSIX
ShardIteratorType
type' :: ShardIteratorType
timestamp :: Maybe POSIX
sequenceNumber :: Maybe Text
$sel:type':StartingPosition' :: StartingPosition -> ShardIteratorType
$sel:timestamp:StartingPosition' :: StartingPosition -> Maybe POSIX
$sel:sequenceNumber:StartingPosition' :: StartingPosition -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
sequenceNumber
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe POSIX
timestamp
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ShardIteratorType
type'

instance Prelude.NFData StartingPosition where
  rnf :: StartingPosition -> ()
rnf StartingPosition' {Maybe Text
Maybe POSIX
ShardIteratorType
type' :: ShardIteratorType
timestamp :: Maybe POSIX
sequenceNumber :: Maybe Text
$sel:type':StartingPosition' :: StartingPosition -> ShardIteratorType
$sel:timestamp:StartingPosition' :: StartingPosition -> Maybe POSIX
$sel:sequenceNumber:StartingPosition' :: StartingPosition -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
sequenceNumber
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe POSIX
timestamp
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf ShardIteratorType
type'

instance Data.ToJSON StartingPosition where
  toJSON :: StartingPosition -> Value
toJSON StartingPosition' {Maybe Text
Maybe POSIX
ShardIteratorType
type' :: ShardIteratorType
timestamp :: Maybe POSIX
sequenceNumber :: Maybe Text
$sel:type':StartingPosition' :: StartingPosition -> ShardIteratorType
$sel:timestamp:StartingPosition' :: StartingPosition -> Maybe POSIX
$sel:sequenceNumber:StartingPosition' :: StartingPosition -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"SequenceNumber" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
sequenceNumber,
            (Key
"Timestamp" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe POSIX
timestamp,
            forall a. a -> Maybe a
Prelude.Just (Key
"Type" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= ShardIteratorType
type')
          ]
      )