{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.DynamoDBStreams.DescribeStream
-- 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)
--
-- Returns information about a stream, including the current status of the
-- stream, its Amazon Resource Name (ARN), the composition of its shards,
-- and its corresponding DynamoDB table.
--
-- You can call @DescribeStream@ at a maximum rate of 10 times per second.
--
-- Each shard in the stream has a @SequenceNumberRange@ associated with it.
-- If the @SequenceNumberRange@ has a @StartingSequenceNumber@ but no
-- @EndingSequenceNumber@, then the shard is still open (able to receive
-- more stream records). If both @StartingSequenceNumber@ and
-- @EndingSequenceNumber@ are present, then that shard is closed and can no
-- longer receive more data.
module Amazonka.DynamoDBStreams.DescribeStream
  ( -- * Creating a Request
    DescribeStream (..),
    newDescribeStream,

    -- * Request Lenses
    describeStream_exclusiveStartShardId,
    describeStream_limit,
    describeStream_streamArn,

    -- * Destructuring the Response
    DescribeStreamResponse (..),
    newDescribeStreamResponse,

    -- * Response Lenses
    describeStreamResponse_streamDescription,
    describeStreamResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.DynamoDBStreams.Types
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | Represents the input of a @DescribeStream@ operation.
--
-- /See:/ 'newDescribeStream' smart constructor.
data DescribeStream = DescribeStream'
  { -- | The shard ID of the first item that this operation will evaluate. Use
    -- the value that was returned for @LastEvaluatedShardId@ in the previous
    -- operation.
    DescribeStream -> Maybe Text
exclusiveStartShardId :: Prelude.Maybe Prelude.Text,
    -- | The maximum number of shard objects to return. The upper limit is 100.
    DescribeStream -> Maybe Natural
limit :: Prelude.Maybe Prelude.Natural,
    -- | The Amazon Resource Name (ARN) for the stream.
    DescribeStream -> Text
streamArn :: Prelude.Text
  }
  deriving (DescribeStream -> DescribeStream -> Bool
(DescribeStream -> DescribeStream -> Bool)
-> (DescribeStream -> DescribeStream -> Bool) -> Eq DescribeStream
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeStream -> DescribeStream -> Bool
$c/= :: DescribeStream -> DescribeStream -> Bool
== :: DescribeStream -> DescribeStream -> Bool
$c== :: DescribeStream -> DescribeStream -> Bool
Prelude.Eq, ReadPrec [DescribeStream]
ReadPrec DescribeStream
Int -> ReadS DescribeStream
ReadS [DescribeStream]
(Int -> ReadS DescribeStream)
-> ReadS [DescribeStream]
-> ReadPrec DescribeStream
-> ReadPrec [DescribeStream]
-> Read DescribeStream
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribeStream]
$creadListPrec :: ReadPrec [DescribeStream]
readPrec :: ReadPrec DescribeStream
$creadPrec :: ReadPrec DescribeStream
readList :: ReadS [DescribeStream]
$creadList :: ReadS [DescribeStream]
readsPrec :: Int -> ReadS DescribeStream
$creadsPrec :: Int -> ReadS DescribeStream
Prelude.Read, Int -> DescribeStream -> ShowS
[DescribeStream] -> ShowS
DescribeStream -> String
(Int -> DescribeStream -> ShowS)
-> (DescribeStream -> String)
-> ([DescribeStream] -> ShowS)
-> Show DescribeStream
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeStream] -> ShowS
$cshowList :: [DescribeStream] -> ShowS
show :: DescribeStream -> String
$cshow :: DescribeStream -> String
showsPrec :: Int -> DescribeStream -> ShowS
$cshowsPrec :: Int -> DescribeStream -> ShowS
Prelude.Show, (forall x. DescribeStream -> Rep DescribeStream x)
-> (forall x. Rep DescribeStream x -> DescribeStream)
-> Generic DescribeStream
forall x. Rep DescribeStream x -> DescribeStream
forall x. DescribeStream -> Rep DescribeStream x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DescribeStream x -> DescribeStream
$cfrom :: forall x. DescribeStream -> Rep DescribeStream x
Prelude.Generic)

-- |
-- Create a value of 'DescribeStream' 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:
--
-- 'exclusiveStartShardId', 'describeStream_exclusiveStartShardId' - The shard ID of the first item that this operation will evaluate. Use
-- the value that was returned for @LastEvaluatedShardId@ in the previous
-- operation.
--
-- 'limit', 'describeStream_limit' - The maximum number of shard objects to return. The upper limit is 100.
--
-- 'streamArn', 'describeStream_streamArn' - The Amazon Resource Name (ARN) for the stream.
newDescribeStream ::
  -- | 'streamArn'
  Prelude.Text ->
  DescribeStream
newDescribeStream :: Text -> DescribeStream
newDescribeStream Text
pStreamArn_ =
  DescribeStream' :: Maybe Text -> Maybe Natural -> Text -> DescribeStream
DescribeStream'
    { $sel:exclusiveStartShardId:DescribeStream' :: Maybe Text
exclusiveStartShardId =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:limit:DescribeStream' :: Maybe Natural
limit = Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:streamArn:DescribeStream' :: Text
streamArn = Text
pStreamArn_
    }

-- | The shard ID of the first item that this operation will evaluate. Use
-- the value that was returned for @LastEvaluatedShardId@ in the previous
-- operation.
describeStream_exclusiveStartShardId :: Lens.Lens' DescribeStream (Prelude.Maybe Prelude.Text)
describeStream_exclusiveStartShardId :: (Maybe Text -> f (Maybe Text))
-> DescribeStream -> f DescribeStream
describeStream_exclusiveStartShardId = (DescribeStream -> Maybe Text)
-> (DescribeStream -> Maybe Text -> DescribeStream)
-> Lens DescribeStream DescribeStream (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeStream' {Maybe Text
exclusiveStartShardId :: Maybe Text
$sel:exclusiveStartShardId:DescribeStream' :: DescribeStream -> Maybe Text
exclusiveStartShardId} -> Maybe Text
exclusiveStartShardId) (\s :: DescribeStream
s@DescribeStream' {} Maybe Text
a -> DescribeStream
s {$sel:exclusiveStartShardId:DescribeStream' :: Maybe Text
exclusiveStartShardId = Maybe Text
a} :: DescribeStream)

-- | The maximum number of shard objects to return. The upper limit is 100.
describeStream_limit :: Lens.Lens' DescribeStream (Prelude.Maybe Prelude.Natural)
describeStream_limit :: (Maybe Natural -> f (Maybe Natural))
-> DescribeStream -> f DescribeStream
describeStream_limit = (DescribeStream -> Maybe Natural)
-> (DescribeStream -> Maybe Natural -> DescribeStream)
-> Lens
     DescribeStream DescribeStream (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeStream' {Maybe Natural
limit :: Maybe Natural
$sel:limit:DescribeStream' :: DescribeStream -> Maybe Natural
limit} -> Maybe Natural
limit) (\s :: DescribeStream
s@DescribeStream' {} Maybe Natural
a -> DescribeStream
s {$sel:limit:DescribeStream' :: Maybe Natural
limit = Maybe Natural
a} :: DescribeStream)

-- | The Amazon Resource Name (ARN) for the stream.
describeStream_streamArn :: Lens.Lens' DescribeStream Prelude.Text
describeStream_streamArn :: (Text -> f Text) -> DescribeStream -> f DescribeStream
describeStream_streamArn = (DescribeStream -> Text)
-> (DescribeStream -> Text -> DescribeStream)
-> Lens DescribeStream DescribeStream Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeStream' {Text
streamArn :: Text
$sel:streamArn:DescribeStream' :: DescribeStream -> Text
streamArn} -> Text
streamArn) (\s :: DescribeStream
s@DescribeStream' {} Text
a -> DescribeStream
s {$sel:streamArn:DescribeStream' :: Text
streamArn = Text
a} :: DescribeStream)

instance Core.AWSRequest DescribeStream where
  type
    AWSResponse DescribeStream =
      DescribeStreamResponse
  request :: DescribeStream -> Request DescribeStream
request = Service -> DescribeStream -> Request DescribeStream
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy DescribeStream
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DescribeStream)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse DescribeStream))
-> Logger
-> Service
-> Proxy DescribeStream
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DescribeStream)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe StreamDescription -> Int -> DescribeStreamResponse
DescribeStreamResponse'
            (Maybe StreamDescription -> Int -> DescribeStreamResponse)
-> Either String (Maybe StreamDescription)
-> Either String (Int -> DescribeStreamResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe StreamDescription)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"StreamDescription")
            Either String (Int -> DescribeStreamResponse)
-> Either String Int -> Either String DescribeStreamResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable DescribeStream

instance Prelude.NFData DescribeStream

instance Core.ToHeaders DescribeStream where
  toHeaders :: DescribeStream -> ResponseHeaders
toHeaders =
    ResponseHeaders -> DescribeStream -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"DynamoDBStreams_20120810.DescribeStream" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.0" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON DescribeStream where
  toJSON :: DescribeStream -> Value
toJSON DescribeStream' {Maybe Natural
Maybe Text
Text
streamArn :: Text
limit :: Maybe Natural
exclusiveStartShardId :: Maybe Text
$sel:streamArn:DescribeStream' :: DescribeStream -> Text
$sel:limit:DescribeStream' :: DescribeStream -> Maybe Natural
$sel:exclusiveStartShardId:DescribeStream' :: DescribeStream -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"ExclusiveStartShardId" 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
exclusiveStartShardId,
            (Text
"Limit" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
limit,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"StreamArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
streamArn)
          ]
      )

instance Core.ToPath DescribeStream where
  toPath :: DescribeStream -> ByteString
toPath = ByteString -> DescribeStream -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Core.ToQuery DescribeStream where
  toQuery :: DescribeStream -> QueryString
toQuery = QueryString -> DescribeStream -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | Represents the output of a @DescribeStream@ operation.
--
-- /See:/ 'newDescribeStreamResponse' smart constructor.
data DescribeStreamResponse = DescribeStreamResponse'
  { -- | A complete description of the stream, including its creation date and
    -- time, the DynamoDB table associated with the stream, the shard IDs
    -- within the stream, and the beginning and ending sequence numbers of
    -- stream records within the shards.
    DescribeStreamResponse -> Maybe StreamDescription
streamDescription :: Prelude.Maybe StreamDescription,
    -- | The response's http status code.
    DescribeStreamResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (DescribeStreamResponse -> DescribeStreamResponse -> Bool
(DescribeStreamResponse -> DescribeStreamResponse -> Bool)
-> (DescribeStreamResponse -> DescribeStreamResponse -> Bool)
-> Eq DescribeStreamResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeStreamResponse -> DescribeStreamResponse -> Bool
$c/= :: DescribeStreamResponse -> DescribeStreamResponse -> Bool
== :: DescribeStreamResponse -> DescribeStreamResponse -> Bool
$c== :: DescribeStreamResponse -> DescribeStreamResponse -> Bool
Prelude.Eq, ReadPrec [DescribeStreamResponse]
ReadPrec DescribeStreamResponse
Int -> ReadS DescribeStreamResponse
ReadS [DescribeStreamResponse]
(Int -> ReadS DescribeStreamResponse)
-> ReadS [DescribeStreamResponse]
-> ReadPrec DescribeStreamResponse
-> ReadPrec [DescribeStreamResponse]
-> Read DescribeStreamResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribeStreamResponse]
$creadListPrec :: ReadPrec [DescribeStreamResponse]
readPrec :: ReadPrec DescribeStreamResponse
$creadPrec :: ReadPrec DescribeStreamResponse
readList :: ReadS [DescribeStreamResponse]
$creadList :: ReadS [DescribeStreamResponse]
readsPrec :: Int -> ReadS DescribeStreamResponse
$creadsPrec :: Int -> ReadS DescribeStreamResponse
Prelude.Read, Int -> DescribeStreamResponse -> ShowS
[DescribeStreamResponse] -> ShowS
DescribeStreamResponse -> String
(Int -> DescribeStreamResponse -> ShowS)
-> (DescribeStreamResponse -> String)
-> ([DescribeStreamResponse] -> ShowS)
-> Show DescribeStreamResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeStreamResponse] -> ShowS
$cshowList :: [DescribeStreamResponse] -> ShowS
show :: DescribeStreamResponse -> String
$cshow :: DescribeStreamResponse -> String
showsPrec :: Int -> DescribeStreamResponse -> ShowS
$cshowsPrec :: Int -> DescribeStreamResponse -> ShowS
Prelude.Show, (forall x. DescribeStreamResponse -> Rep DescribeStreamResponse x)
-> (forall x.
    Rep DescribeStreamResponse x -> DescribeStreamResponse)
-> Generic DescribeStreamResponse
forall x. Rep DescribeStreamResponse x -> DescribeStreamResponse
forall x. DescribeStreamResponse -> Rep DescribeStreamResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DescribeStreamResponse x -> DescribeStreamResponse
$cfrom :: forall x. DescribeStreamResponse -> Rep DescribeStreamResponse x
Prelude.Generic)

-- |
-- Create a value of 'DescribeStreamResponse' 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:
--
-- 'streamDescription', 'describeStreamResponse_streamDescription' - A complete description of the stream, including its creation date and
-- time, the DynamoDB table associated with the stream, the shard IDs
-- within the stream, and the beginning and ending sequence numbers of
-- stream records within the shards.
--
-- 'httpStatus', 'describeStreamResponse_httpStatus' - The response's http status code.
newDescribeStreamResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DescribeStreamResponse
newDescribeStreamResponse :: Int -> DescribeStreamResponse
newDescribeStreamResponse Int
pHttpStatus_ =
  DescribeStreamResponse' :: Maybe StreamDescription -> Int -> DescribeStreamResponse
DescribeStreamResponse'
    { $sel:streamDescription:DescribeStreamResponse' :: Maybe StreamDescription
streamDescription =
        Maybe StreamDescription
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DescribeStreamResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A complete description of the stream, including its creation date and
-- time, the DynamoDB table associated with the stream, the shard IDs
-- within the stream, and the beginning and ending sequence numbers of
-- stream records within the shards.
describeStreamResponse_streamDescription :: Lens.Lens' DescribeStreamResponse (Prelude.Maybe StreamDescription)
describeStreamResponse_streamDescription :: (Maybe StreamDescription -> f (Maybe StreamDescription))
-> DescribeStreamResponse -> f DescribeStreamResponse
describeStreamResponse_streamDescription = (DescribeStreamResponse -> Maybe StreamDescription)
-> (DescribeStreamResponse
    -> Maybe StreamDescription -> DescribeStreamResponse)
-> Lens
     DescribeStreamResponse
     DescribeStreamResponse
     (Maybe StreamDescription)
     (Maybe StreamDescription)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeStreamResponse' {Maybe StreamDescription
streamDescription :: Maybe StreamDescription
$sel:streamDescription:DescribeStreamResponse' :: DescribeStreamResponse -> Maybe StreamDescription
streamDescription} -> Maybe StreamDescription
streamDescription) (\s :: DescribeStreamResponse
s@DescribeStreamResponse' {} Maybe StreamDescription
a -> DescribeStreamResponse
s {$sel:streamDescription:DescribeStreamResponse' :: Maybe StreamDescription
streamDescription = Maybe StreamDescription
a} :: DescribeStreamResponse)

-- | The response's http status code.
describeStreamResponse_httpStatus :: Lens.Lens' DescribeStreamResponse Prelude.Int
describeStreamResponse_httpStatus :: (Int -> f Int)
-> DescribeStreamResponse -> f DescribeStreamResponse
describeStreamResponse_httpStatus = (DescribeStreamResponse -> Int)
-> (DescribeStreamResponse -> Int -> DescribeStreamResponse)
-> Lens DescribeStreamResponse DescribeStreamResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeStreamResponse' {Int
httpStatus :: Int
$sel:httpStatus:DescribeStreamResponse' :: DescribeStreamResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: DescribeStreamResponse
s@DescribeStreamResponse' {} Int
a -> DescribeStreamResponse
s {$sel:httpStatus:DescribeStreamResponse' :: Int
httpStatus = Int
a} :: DescribeStreamResponse)

instance Prelude.NFData DescribeStreamResponse