{-# 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.KinesisVideoMedia.Types.StartSelector
-- 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.KinesisVideoMedia.Types.StartSelector where

import qualified Amazonka.Core as Core
import Amazonka.KinesisVideoMedia.Types.StartSelectorType
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Identifies the chunk on the Kinesis video stream where you want the
-- @GetMedia@ API to start returning media data. You have the following
-- options to identify the starting chunk:
--
-- -   Choose the latest (or oldest) chunk.
--
-- -   Identify a specific chunk. You can identify a specific chunk either
--     by providing a fragment number or timestamp (server or producer).
--
-- -   Each chunk\'s metadata includes a continuation token as a Matroska
--     (MKV) tag (@AWS_KINESISVIDEO_CONTINUATION_TOKEN@). If your previous
--     @GetMedia@ request terminated, you can use this tag value in your
--     next @GetMedia@ request. The API then starts returning chunks
--     starting where the last API ended.
--
-- /See:/ 'newStartSelector' smart constructor.
data StartSelector = StartSelector'
  { -- | Continuation token that Kinesis Video Streams returned in the previous
    -- @GetMedia@ response. The @GetMedia@ API then starts with the chunk
    -- identified by the continuation token.
    StartSelector -> Maybe Text
continuationToken :: Prelude.Maybe Prelude.Text,
    -- | Specifies the fragment number from where you want the @GetMedia@ API to
    -- start returning the fragments.
    StartSelector -> Maybe Text
afterFragmentNumber :: Prelude.Maybe Prelude.Text,
    -- | A timestamp value. This value is required if you choose the
    -- PRODUCER_TIMESTAMP or the SERVER_TIMESTAMP as the @startSelectorType@.
    -- The @GetMedia@ API then starts with the chunk containing the fragment
    -- that has the specified timestamp.
    StartSelector -> Maybe POSIX
startTimestamp :: Prelude.Maybe Core.POSIX,
    -- | Identifies the fragment on the Kinesis video stream where you want to
    -- start getting the data from.
    --
    -- -   NOW - Start with the latest chunk on the stream.
    --
    -- -   EARLIEST - Start with earliest available chunk on the stream.
    --
    -- -   FRAGMENT_NUMBER - Start with the chunk after a specific fragment.
    --     You must also specify the @AfterFragmentNumber@ parameter.
    --
    -- -   PRODUCER_TIMESTAMP or SERVER_TIMESTAMP - Start with the chunk
    --     containing a fragment with the specified producer or server
    --     timestamp. You specify the timestamp by adding @StartTimestamp@.
    --
    -- -   CONTINUATION_TOKEN - Read using the specified continuation token.
    --
    -- If you choose the NOW, EARLIEST, or CONTINUATION_TOKEN as the
    -- @startSelectorType@, you don\'t provide any additional information in
    -- the @startSelector@.
    StartSelector -> StartSelectorType
startSelectorType :: StartSelectorType
  }
  deriving (StartSelector -> StartSelector -> Bool
(StartSelector -> StartSelector -> Bool)
-> (StartSelector -> StartSelector -> Bool) -> Eq StartSelector
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StartSelector -> StartSelector -> Bool
$c/= :: StartSelector -> StartSelector -> Bool
== :: StartSelector -> StartSelector -> Bool
$c== :: StartSelector -> StartSelector -> Bool
Prelude.Eq, ReadPrec [StartSelector]
ReadPrec StartSelector
Int -> ReadS StartSelector
ReadS [StartSelector]
(Int -> ReadS StartSelector)
-> ReadS [StartSelector]
-> ReadPrec StartSelector
-> ReadPrec [StartSelector]
-> Read StartSelector
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StartSelector]
$creadListPrec :: ReadPrec [StartSelector]
readPrec :: ReadPrec StartSelector
$creadPrec :: ReadPrec StartSelector
readList :: ReadS [StartSelector]
$creadList :: ReadS [StartSelector]
readsPrec :: Int -> ReadS StartSelector
$creadsPrec :: Int -> ReadS StartSelector
Prelude.Read, Int -> StartSelector -> ShowS
[StartSelector] -> ShowS
StartSelector -> String
(Int -> StartSelector -> ShowS)
-> (StartSelector -> String)
-> ([StartSelector] -> ShowS)
-> Show StartSelector
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StartSelector] -> ShowS
$cshowList :: [StartSelector] -> ShowS
show :: StartSelector -> String
$cshow :: StartSelector -> String
showsPrec :: Int -> StartSelector -> ShowS
$cshowsPrec :: Int -> StartSelector -> ShowS
Prelude.Show, (forall x. StartSelector -> Rep StartSelector x)
-> (forall x. Rep StartSelector x -> StartSelector)
-> Generic StartSelector
forall x. Rep StartSelector x -> StartSelector
forall x. StartSelector -> Rep StartSelector x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StartSelector x -> StartSelector
$cfrom :: forall x. StartSelector -> Rep StartSelector x
Prelude.Generic)

-- |
-- Create a value of 'StartSelector' 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:
--
-- 'continuationToken', 'startSelector_continuationToken' - Continuation token that Kinesis Video Streams returned in the previous
-- @GetMedia@ response. The @GetMedia@ API then starts with the chunk
-- identified by the continuation token.
--
-- 'afterFragmentNumber', 'startSelector_afterFragmentNumber' - Specifies the fragment number from where you want the @GetMedia@ API to
-- start returning the fragments.
--
-- 'startTimestamp', 'startSelector_startTimestamp' - A timestamp value. This value is required if you choose the
-- PRODUCER_TIMESTAMP or the SERVER_TIMESTAMP as the @startSelectorType@.
-- The @GetMedia@ API then starts with the chunk containing the fragment
-- that has the specified timestamp.
--
-- 'startSelectorType', 'startSelector_startSelectorType' - Identifies the fragment on the Kinesis video stream where you want to
-- start getting the data from.
--
-- -   NOW - Start with the latest chunk on the stream.
--
-- -   EARLIEST - Start with earliest available chunk on the stream.
--
-- -   FRAGMENT_NUMBER - Start with the chunk after a specific fragment.
--     You must also specify the @AfterFragmentNumber@ parameter.
--
-- -   PRODUCER_TIMESTAMP or SERVER_TIMESTAMP - Start with the chunk
--     containing a fragment with the specified producer or server
--     timestamp. You specify the timestamp by adding @StartTimestamp@.
--
-- -   CONTINUATION_TOKEN - Read using the specified continuation token.
--
-- If you choose the NOW, EARLIEST, or CONTINUATION_TOKEN as the
-- @startSelectorType@, you don\'t provide any additional information in
-- the @startSelector@.
newStartSelector ::
  -- | 'startSelectorType'
  StartSelectorType ->
  StartSelector
newStartSelector :: StartSelectorType -> StartSelector
newStartSelector StartSelectorType
pStartSelectorType_ =
  StartSelector' :: Maybe Text
-> Maybe Text -> Maybe POSIX -> StartSelectorType -> StartSelector
StartSelector'
    { $sel:continuationToken:StartSelector' :: Maybe Text
continuationToken = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:afterFragmentNumber:StartSelector' :: Maybe Text
afterFragmentNumber = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:startTimestamp:StartSelector' :: Maybe POSIX
startTimestamp = Maybe POSIX
forall a. Maybe a
Prelude.Nothing,
      $sel:startSelectorType:StartSelector' :: StartSelectorType
startSelectorType = StartSelectorType
pStartSelectorType_
    }

-- | Continuation token that Kinesis Video Streams returned in the previous
-- @GetMedia@ response. The @GetMedia@ API then starts with the chunk
-- identified by the continuation token.
startSelector_continuationToken :: Lens.Lens' StartSelector (Prelude.Maybe Prelude.Text)
startSelector_continuationToken :: (Maybe Text -> f (Maybe Text)) -> StartSelector -> f StartSelector
startSelector_continuationToken = (StartSelector -> Maybe Text)
-> (StartSelector -> Maybe Text -> StartSelector)
-> Lens StartSelector StartSelector (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartSelector' {Maybe Text
continuationToken :: Maybe Text
$sel:continuationToken:StartSelector' :: StartSelector -> Maybe Text
continuationToken} -> Maybe Text
continuationToken) (\s :: StartSelector
s@StartSelector' {} Maybe Text
a -> StartSelector
s {$sel:continuationToken:StartSelector' :: Maybe Text
continuationToken = Maybe Text
a} :: StartSelector)

-- | Specifies the fragment number from where you want the @GetMedia@ API to
-- start returning the fragments.
startSelector_afterFragmentNumber :: Lens.Lens' StartSelector (Prelude.Maybe Prelude.Text)
startSelector_afterFragmentNumber :: (Maybe Text -> f (Maybe Text)) -> StartSelector -> f StartSelector
startSelector_afterFragmentNumber = (StartSelector -> Maybe Text)
-> (StartSelector -> Maybe Text -> StartSelector)
-> Lens StartSelector StartSelector (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartSelector' {Maybe Text
afterFragmentNumber :: Maybe Text
$sel:afterFragmentNumber:StartSelector' :: StartSelector -> Maybe Text
afterFragmentNumber} -> Maybe Text
afterFragmentNumber) (\s :: StartSelector
s@StartSelector' {} Maybe Text
a -> StartSelector
s {$sel:afterFragmentNumber:StartSelector' :: Maybe Text
afterFragmentNumber = Maybe Text
a} :: StartSelector)

-- | A timestamp value. This value is required if you choose the
-- PRODUCER_TIMESTAMP or the SERVER_TIMESTAMP as the @startSelectorType@.
-- The @GetMedia@ API then starts with the chunk containing the fragment
-- that has the specified timestamp.
startSelector_startTimestamp :: Lens.Lens' StartSelector (Prelude.Maybe Prelude.UTCTime)
startSelector_startTimestamp :: (Maybe UTCTime -> f (Maybe UTCTime))
-> StartSelector -> f StartSelector
startSelector_startTimestamp = (StartSelector -> Maybe POSIX)
-> (StartSelector -> Maybe POSIX -> StartSelector)
-> Lens StartSelector StartSelector (Maybe POSIX) (Maybe POSIX)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartSelector' {Maybe POSIX
startTimestamp :: Maybe POSIX
$sel:startTimestamp:StartSelector' :: StartSelector -> Maybe POSIX
startTimestamp} -> Maybe POSIX
startTimestamp) (\s :: StartSelector
s@StartSelector' {} Maybe POSIX
a -> StartSelector
s {$sel:startTimestamp:StartSelector' :: Maybe POSIX
startTimestamp = Maybe POSIX
a} :: StartSelector) ((Maybe POSIX -> f (Maybe POSIX))
 -> StartSelector -> f StartSelector)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> StartSelector
-> f StartSelector
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

-- | Identifies the fragment on the Kinesis video stream where you want to
-- start getting the data from.
--
-- -   NOW - Start with the latest chunk on the stream.
--
-- -   EARLIEST - Start with earliest available chunk on the stream.
--
-- -   FRAGMENT_NUMBER - Start with the chunk after a specific fragment.
--     You must also specify the @AfterFragmentNumber@ parameter.
--
-- -   PRODUCER_TIMESTAMP or SERVER_TIMESTAMP - Start with the chunk
--     containing a fragment with the specified producer or server
--     timestamp. You specify the timestamp by adding @StartTimestamp@.
--
-- -   CONTINUATION_TOKEN - Read using the specified continuation token.
--
-- If you choose the NOW, EARLIEST, or CONTINUATION_TOKEN as the
-- @startSelectorType@, you don\'t provide any additional information in
-- the @startSelector@.
startSelector_startSelectorType :: Lens.Lens' StartSelector StartSelectorType
startSelector_startSelectorType :: (StartSelectorType -> f StartSelectorType)
-> StartSelector -> f StartSelector
startSelector_startSelectorType = (StartSelector -> StartSelectorType)
-> (StartSelector -> StartSelectorType -> StartSelector)
-> Lens
     StartSelector StartSelector StartSelectorType StartSelectorType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartSelector' {StartSelectorType
startSelectorType :: StartSelectorType
$sel:startSelectorType:StartSelector' :: StartSelector -> StartSelectorType
startSelectorType} -> StartSelectorType
startSelectorType) (\s :: StartSelector
s@StartSelector' {} StartSelectorType
a -> StartSelector
s {$sel:startSelectorType:StartSelector' :: StartSelectorType
startSelectorType = StartSelectorType
a} :: StartSelector)

instance Prelude.Hashable StartSelector

instance Prelude.NFData StartSelector

instance Core.ToJSON StartSelector where
  toJSON :: StartSelector -> Value
toJSON StartSelector' {Maybe Text
Maybe POSIX
StartSelectorType
startSelectorType :: StartSelectorType
startTimestamp :: Maybe POSIX
afterFragmentNumber :: Maybe Text
continuationToken :: Maybe Text
$sel:startSelectorType:StartSelector' :: StartSelector -> StartSelectorType
$sel:startTimestamp:StartSelector' :: StartSelector -> Maybe POSIX
$sel:afterFragmentNumber:StartSelector' :: StartSelector -> Maybe Text
$sel:continuationToken:StartSelector' :: StartSelector -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"ContinuationToken" 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
continuationToken,
            (Text
"AfterFragmentNumber" 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
afterFragmentNumber,
            (Text
"StartTimestamp" 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
startTimestamp,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"StartSelectorType" Text -> StartSelectorType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= StartSelectorType
startSelectorType)
          ]
      )