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

import qualified Amazonka.Core as Core
import Amazonka.Kinesis.Types.ShardIteratorType
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- |
--
-- /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 Core.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
(StartingPosition -> StartingPosition -> Bool)
-> (StartingPosition -> StartingPosition -> Bool)
-> Eq StartingPosition
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]
(Int -> ReadS StartingPosition)
-> ReadS [StartingPosition]
-> ReadPrec StartingPosition
-> ReadPrec [StartingPosition]
-> Read 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
(Int -> StartingPosition -> ShowS)
-> (StartingPosition -> String)
-> ([StartingPosition] -> ShowS)
-> Show StartingPosition
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. StartingPosition -> Rep StartingPosition x)
-> (forall x. Rep StartingPosition x -> StartingPosition)
-> Generic StartingPosition
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' :: Maybe Text -> Maybe POSIX -> ShardIteratorType -> StartingPosition
StartingPosition'
    { $sel:sequenceNumber:StartingPosition' :: Maybe Text
sequenceNumber = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:timestamp:StartingPosition' :: Maybe POSIX
timestamp = Maybe POSIX
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 :: (Maybe Text -> f (Maybe Text))
-> StartingPosition -> f StartingPosition
startingPosition_sequenceNumber = (StartingPosition -> Maybe Text)
-> (StartingPosition -> Maybe Text -> StartingPosition)
-> Lens StartingPosition StartingPosition (Maybe Text) (Maybe Text)
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 :: (Maybe UTCTime -> f (Maybe UTCTime))
-> StartingPosition -> f StartingPosition
startingPosition_timestamp = (StartingPosition -> Maybe POSIX)
-> (StartingPosition -> Maybe POSIX -> StartingPosition)
-> Lens
     StartingPosition StartingPosition (Maybe POSIX) (Maybe POSIX)
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) ((Maybe POSIX -> f (Maybe POSIX))
 -> StartingPosition -> f StartingPosition)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> StartingPosition
-> f StartingPosition
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso POSIX POSIX UTCTime UTCTime
-> Iso (Maybe POSIX) (Maybe POSIX) (Maybe UTCTime) (Maybe UTCTime)
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 POSIX POSIX UTCTime UTCTime
forall (a :: Format). Iso' (Time a) UTCTime
Core._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 :: (ShardIteratorType -> f ShardIteratorType)
-> StartingPosition -> f StartingPosition
startingPosition_type = (StartingPosition -> ShardIteratorType)
-> (StartingPosition -> ShardIteratorType -> StartingPosition)
-> Lens
     StartingPosition
     StartingPosition
     ShardIteratorType
     ShardIteratorType
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

instance Prelude.NFData StartingPosition

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"SequenceNumber" 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
sequenceNumber,
            (Text
"Timestamp" Text -> POSIX -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (POSIX -> Pair) -> Maybe POSIX -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe POSIX
timestamp,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Type" Text -> ShardIteratorType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ShardIteratorType
type')
          ]
      )