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

-- | The request parameter used to filter out the response of the
-- @ListShards@ API.
--
-- /See:/ 'newShardFilter' smart constructor.
data ShardFilter = ShardFilter'
  { -- | The exclusive start @shardID@ speified in the @ShardFilter@ parameter.
    -- This property can only be used if the @AFTER_SHARD_ID@ shard type is
    -- specified.
    ShardFilter -> Maybe Text
shardId :: Prelude.Maybe Prelude.Text,
    -- | The timestamps specified in the @ShardFilter@ parameter. A timestamp is
    -- a Unix epoch date with precision in milliseconds. For example,
    -- 2016-04-04T19:58:46.480-00:00 or 1459799926.480. This property can only
    -- be used if @FROM_TIMESTAMP@ or @AT_TIMESTAMP@ shard types are specified.
    ShardFilter -> Maybe POSIX
timestamp :: Prelude.Maybe Data.POSIX,
    -- | The shard type specified in the @ShardFilter@ parameter. This is a
    -- required property of the @ShardFilter@ parameter.
    --
    -- You can specify the following valid values:
    --
    -- -   @AFTER_SHARD_ID@ - the response includes all the shards, starting
    --     with the shard whose ID immediately follows the @ShardId@ that you
    --     provided.
    --
    -- -   @AT_TRIM_HORIZON@ - the response includes all the shards that were
    --     open at @TRIM_HORIZON@.
    --
    -- -   @FROM_TRIM_HORIZON@ - (default), the response includes all the
    --     shards within the retention period of the data stream (trim to tip).
    --
    -- -   @AT_LATEST@ - the response includes only the currently open shards
    --     of the data stream.
    --
    -- -   @AT_TIMESTAMP@ - the response includes all shards whose start
    --     timestamp is less than or equal to the given timestamp and end
    --     timestamp is greater than or equal to the given timestamp or still
    --     open.
    --
    -- -   @FROM_TIMESTAMP@ - the response incldues all closed shards whose end
    --     timestamp is greater than or equal to the given timestamp and also
    --     all open shards. Corrected to @TRIM_HORIZON@ of the data stream if
    --     @FROM_TIMESTAMP@ is less than the @TRIM_HORIZON@ value.
    ShardFilter -> ShardFilterType
type' :: ShardFilterType
  }
  deriving (ShardFilter -> ShardFilter -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ShardFilter -> ShardFilter -> Bool
$c/= :: ShardFilter -> ShardFilter -> Bool
== :: ShardFilter -> ShardFilter -> Bool
$c== :: ShardFilter -> ShardFilter -> Bool
Prelude.Eq, ReadPrec [ShardFilter]
ReadPrec ShardFilter
Int -> ReadS ShardFilter
ReadS [ShardFilter]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ShardFilter]
$creadListPrec :: ReadPrec [ShardFilter]
readPrec :: ReadPrec ShardFilter
$creadPrec :: ReadPrec ShardFilter
readList :: ReadS [ShardFilter]
$creadList :: ReadS [ShardFilter]
readsPrec :: Int -> ReadS ShardFilter
$creadsPrec :: Int -> ReadS ShardFilter
Prelude.Read, Int -> ShardFilter -> ShowS
[ShardFilter] -> ShowS
ShardFilter -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ShardFilter] -> ShowS
$cshowList :: [ShardFilter] -> ShowS
show :: ShardFilter -> String
$cshow :: ShardFilter -> String
showsPrec :: Int -> ShardFilter -> ShowS
$cshowsPrec :: Int -> ShardFilter -> ShowS
Prelude.Show, forall x. Rep ShardFilter x -> ShardFilter
forall x. ShardFilter -> Rep ShardFilter x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ShardFilter x -> ShardFilter
$cfrom :: forall x. ShardFilter -> Rep ShardFilter x
Prelude.Generic)

-- |
-- Create a value of 'ShardFilter' 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:
--
-- 'shardId', 'shardFilter_shardId' - The exclusive start @shardID@ speified in the @ShardFilter@ parameter.
-- This property can only be used if the @AFTER_SHARD_ID@ shard type is
-- specified.
--
-- 'timestamp', 'shardFilter_timestamp' - The timestamps specified in the @ShardFilter@ parameter. A timestamp is
-- a Unix epoch date with precision in milliseconds. For example,
-- 2016-04-04T19:58:46.480-00:00 or 1459799926.480. This property can only
-- be used if @FROM_TIMESTAMP@ or @AT_TIMESTAMP@ shard types are specified.
--
-- 'type'', 'shardFilter_type' - The shard type specified in the @ShardFilter@ parameter. This is a
-- required property of the @ShardFilter@ parameter.
--
-- You can specify the following valid values:
--
-- -   @AFTER_SHARD_ID@ - the response includes all the shards, starting
--     with the shard whose ID immediately follows the @ShardId@ that you
--     provided.
--
-- -   @AT_TRIM_HORIZON@ - the response includes all the shards that were
--     open at @TRIM_HORIZON@.
--
-- -   @FROM_TRIM_HORIZON@ - (default), the response includes all the
--     shards within the retention period of the data stream (trim to tip).
--
-- -   @AT_LATEST@ - the response includes only the currently open shards
--     of the data stream.
--
-- -   @AT_TIMESTAMP@ - the response includes all shards whose start
--     timestamp is less than or equal to the given timestamp and end
--     timestamp is greater than or equal to the given timestamp or still
--     open.
--
-- -   @FROM_TIMESTAMP@ - the response incldues all closed shards whose end
--     timestamp is greater than or equal to the given timestamp and also
--     all open shards. Corrected to @TRIM_HORIZON@ of the data stream if
--     @FROM_TIMESTAMP@ is less than the @TRIM_HORIZON@ value.
newShardFilter ::
  -- | 'type''
  ShardFilterType ->
  ShardFilter
newShardFilter :: ShardFilterType -> ShardFilter
newShardFilter ShardFilterType
pType_ =
  ShardFilter'
    { $sel:shardId:ShardFilter' :: Maybe Text
shardId = forall a. Maybe a
Prelude.Nothing,
      $sel:timestamp:ShardFilter' :: Maybe POSIX
timestamp = forall a. Maybe a
Prelude.Nothing,
      $sel:type':ShardFilter' :: ShardFilterType
type' = ShardFilterType
pType_
    }

-- | The exclusive start @shardID@ speified in the @ShardFilter@ parameter.
-- This property can only be used if the @AFTER_SHARD_ID@ shard type is
-- specified.
shardFilter_shardId :: Lens.Lens' ShardFilter (Prelude.Maybe Prelude.Text)
shardFilter_shardId :: Lens' ShardFilter (Maybe Text)
shardFilter_shardId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ShardFilter' {Maybe Text
shardId :: Maybe Text
$sel:shardId:ShardFilter' :: ShardFilter -> Maybe Text
shardId} -> Maybe Text
shardId) (\s :: ShardFilter
s@ShardFilter' {} Maybe Text
a -> ShardFilter
s {$sel:shardId:ShardFilter' :: Maybe Text
shardId = Maybe Text
a} :: ShardFilter)

-- | The timestamps specified in the @ShardFilter@ parameter. A timestamp is
-- a Unix epoch date with precision in milliseconds. For example,
-- 2016-04-04T19:58:46.480-00:00 or 1459799926.480. This property can only
-- be used if @FROM_TIMESTAMP@ or @AT_TIMESTAMP@ shard types are specified.
shardFilter_timestamp :: Lens.Lens' ShardFilter (Prelude.Maybe Prelude.UTCTime)
shardFilter_timestamp :: Lens' ShardFilter (Maybe UTCTime)
shardFilter_timestamp = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ShardFilter' {Maybe POSIX
timestamp :: Maybe POSIX
$sel:timestamp:ShardFilter' :: ShardFilter -> Maybe POSIX
timestamp} -> Maybe POSIX
timestamp) (\s :: ShardFilter
s@ShardFilter' {} Maybe POSIX
a -> ShardFilter
s {$sel:timestamp:ShardFilter' :: Maybe POSIX
timestamp = Maybe POSIX
a} :: ShardFilter) 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

-- | The shard type specified in the @ShardFilter@ parameter. This is a
-- required property of the @ShardFilter@ parameter.
--
-- You can specify the following valid values:
--
-- -   @AFTER_SHARD_ID@ - the response includes all the shards, starting
--     with the shard whose ID immediately follows the @ShardId@ that you
--     provided.
--
-- -   @AT_TRIM_HORIZON@ - the response includes all the shards that were
--     open at @TRIM_HORIZON@.
--
-- -   @FROM_TRIM_HORIZON@ - (default), the response includes all the
--     shards within the retention period of the data stream (trim to tip).
--
-- -   @AT_LATEST@ - the response includes only the currently open shards
--     of the data stream.
--
-- -   @AT_TIMESTAMP@ - the response includes all shards whose start
--     timestamp is less than or equal to the given timestamp and end
--     timestamp is greater than or equal to the given timestamp or still
--     open.
--
-- -   @FROM_TIMESTAMP@ - the response incldues all closed shards whose end
--     timestamp is greater than or equal to the given timestamp and also
--     all open shards. Corrected to @TRIM_HORIZON@ of the data stream if
--     @FROM_TIMESTAMP@ is less than the @TRIM_HORIZON@ value.
shardFilter_type :: Lens.Lens' ShardFilter ShardFilterType
shardFilter_type :: Lens' ShardFilter ShardFilterType
shardFilter_type = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ShardFilter' {ShardFilterType
type' :: ShardFilterType
$sel:type':ShardFilter' :: ShardFilter -> ShardFilterType
type'} -> ShardFilterType
type') (\s :: ShardFilter
s@ShardFilter' {} ShardFilterType
a -> ShardFilter
s {$sel:type':ShardFilter' :: ShardFilterType
type' = ShardFilterType
a} :: ShardFilter)

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

instance Prelude.NFData ShardFilter where
  rnf :: ShardFilter -> ()
rnf ShardFilter' {Maybe Text
Maybe POSIX
ShardFilterType
type' :: ShardFilterType
timestamp :: Maybe POSIX
shardId :: Maybe Text
$sel:type':ShardFilter' :: ShardFilter -> ShardFilterType
$sel:timestamp:ShardFilter' :: ShardFilter -> Maybe POSIX
$sel:shardId:ShardFilter' :: ShardFilter -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
shardId
      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 ShardFilterType
type'

instance Data.ToJSON ShardFilter where
  toJSON :: ShardFilter -> Value
toJSON ShardFilter' {Maybe Text
Maybe POSIX
ShardFilterType
type' :: ShardFilterType
timestamp :: Maybe POSIX
shardId :: Maybe Text
$sel:type':ShardFilter' :: ShardFilter -> ShardFilterType
$sel:timestamp:ShardFilter' :: ShardFilter -> Maybe POSIX
$sel:shardId:ShardFilter' :: ShardFilter -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"ShardId" 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
shardId,
            (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..= ShardFilterType
type')
          ]
      )