{-# 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.Kinesis.DeleteStream
-- 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)
--
-- Deletes a Kinesis data stream and all its shards and data. You must shut
-- down any applications that are operating on the stream before you delete
-- the stream. If an application attempts to operate on a deleted stream,
-- it receives the exception @ResourceNotFoundException@.
--
-- If the stream is in the @ACTIVE@ state, you can delete it. After a
-- @DeleteStream@ request, the specified stream is in the @DELETING@ state
-- until Kinesis Data Streams completes the deletion.
--
-- __Note:__ Kinesis Data Streams might continue to accept data read and
-- write operations, such as PutRecord, PutRecords, and GetRecords, on a
-- stream in the @DELETING@ state until the stream deletion is complete.
--
-- When you delete a stream, any shards in that stream are also deleted,
-- and any tags are dissociated from the stream.
--
-- You can use the DescribeStream operation to check the state of the
-- stream, which is returned in @StreamStatus@.
--
-- DeleteStream has a limit of five transactions per second per account.
module Amazonka.Kinesis.DeleteStream
  ( -- * Creating a Request
    DeleteStream (..),
    newDeleteStream,

    -- * Request Lenses
    deleteStream_enforceConsumerDeletion,
    deleteStream_streamName,

    -- * Destructuring the Response
    DeleteStreamResponse (..),
    newDeleteStreamResponse,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.Kinesis.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 for DeleteStream.
--
-- /See:/ 'newDeleteStream' smart constructor.
data DeleteStream = DeleteStream'
  { -- | If this parameter is unset (@null@) or if you set it to @false@, and the
    -- stream has registered consumers, the call to @DeleteStream@ fails with a
    -- @ResourceInUseException@.
    DeleteStream -> Maybe Bool
enforceConsumerDeletion :: Prelude.Maybe Prelude.Bool,
    -- | The name of the stream to delete.
    DeleteStream -> Text
streamName :: Prelude.Text
  }
  deriving (DeleteStream -> DeleteStream -> Bool
(DeleteStream -> DeleteStream -> Bool)
-> (DeleteStream -> DeleteStream -> Bool) -> Eq DeleteStream
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeleteStream -> DeleteStream -> Bool
$c/= :: DeleteStream -> DeleteStream -> Bool
== :: DeleteStream -> DeleteStream -> Bool
$c== :: DeleteStream -> DeleteStream -> Bool
Prelude.Eq, ReadPrec [DeleteStream]
ReadPrec DeleteStream
Int -> ReadS DeleteStream
ReadS [DeleteStream]
(Int -> ReadS DeleteStream)
-> ReadS [DeleteStream]
-> ReadPrec DeleteStream
-> ReadPrec [DeleteStream]
-> Read DeleteStream
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeleteStream]
$creadListPrec :: ReadPrec [DeleteStream]
readPrec :: ReadPrec DeleteStream
$creadPrec :: ReadPrec DeleteStream
readList :: ReadS [DeleteStream]
$creadList :: ReadS [DeleteStream]
readsPrec :: Int -> ReadS DeleteStream
$creadsPrec :: Int -> ReadS DeleteStream
Prelude.Read, Int -> DeleteStream -> ShowS
[DeleteStream] -> ShowS
DeleteStream -> String
(Int -> DeleteStream -> ShowS)
-> (DeleteStream -> String)
-> ([DeleteStream] -> ShowS)
-> Show DeleteStream
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteStream] -> ShowS
$cshowList :: [DeleteStream] -> ShowS
show :: DeleteStream -> String
$cshow :: DeleteStream -> String
showsPrec :: Int -> DeleteStream -> ShowS
$cshowsPrec :: Int -> DeleteStream -> ShowS
Prelude.Show, (forall x. DeleteStream -> Rep DeleteStream x)
-> (forall x. Rep DeleteStream x -> DeleteStream)
-> Generic DeleteStream
forall x. Rep DeleteStream x -> DeleteStream
forall x. DeleteStream -> Rep DeleteStream x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeleteStream x -> DeleteStream
$cfrom :: forall x. DeleteStream -> Rep DeleteStream x
Prelude.Generic)

-- |
-- Create a value of 'DeleteStream' 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:
--
-- 'enforceConsumerDeletion', 'deleteStream_enforceConsumerDeletion' - If this parameter is unset (@null@) or if you set it to @false@, and the
-- stream has registered consumers, the call to @DeleteStream@ fails with a
-- @ResourceInUseException@.
--
-- 'streamName', 'deleteStream_streamName' - The name of the stream to delete.
newDeleteStream ::
  -- | 'streamName'
  Prelude.Text ->
  DeleteStream
newDeleteStream :: Text -> DeleteStream
newDeleteStream Text
pStreamName_ =
  DeleteStream' :: Maybe Bool -> Text -> DeleteStream
DeleteStream'
    { $sel:enforceConsumerDeletion:DeleteStream' :: Maybe Bool
enforceConsumerDeletion =
        Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:streamName:DeleteStream' :: Text
streamName = Text
pStreamName_
    }

-- | If this parameter is unset (@null@) or if you set it to @false@, and the
-- stream has registered consumers, the call to @DeleteStream@ fails with a
-- @ResourceInUseException@.
deleteStream_enforceConsumerDeletion :: Lens.Lens' DeleteStream (Prelude.Maybe Prelude.Bool)
deleteStream_enforceConsumerDeletion :: (Maybe Bool -> f (Maybe Bool)) -> DeleteStream -> f DeleteStream
deleteStream_enforceConsumerDeletion = (DeleteStream -> Maybe Bool)
-> (DeleteStream -> Maybe Bool -> DeleteStream)
-> Lens DeleteStream DeleteStream (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteStream' {Maybe Bool
enforceConsumerDeletion :: Maybe Bool
$sel:enforceConsumerDeletion:DeleteStream' :: DeleteStream -> Maybe Bool
enforceConsumerDeletion} -> Maybe Bool
enforceConsumerDeletion) (\s :: DeleteStream
s@DeleteStream' {} Maybe Bool
a -> DeleteStream
s {$sel:enforceConsumerDeletion:DeleteStream' :: Maybe Bool
enforceConsumerDeletion = Maybe Bool
a} :: DeleteStream)

-- | The name of the stream to delete.
deleteStream_streamName :: Lens.Lens' DeleteStream Prelude.Text
deleteStream_streamName :: (Text -> f Text) -> DeleteStream -> f DeleteStream
deleteStream_streamName = (DeleteStream -> Text)
-> (DeleteStream -> Text -> DeleteStream)
-> Lens DeleteStream DeleteStream Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteStream' {Text
streamName :: Text
$sel:streamName:DeleteStream' :: DeleteStream -> Text
streamName} -> Text
streamName) (\s :: DeleteStream
s@DeleteStream' {} Text
a -> DeleteStream
s {$sel:streamName:DeleteStream' :: Text
streamName = Text
a} :: DeleteStream)

instance Core.AWSRequest DeleteStream where
  type AWSResponse DeleteStream = DeleteStreamResponse
  request :: DeleteStream -> Request DeleteStream
request = Service -> DeleteStream -> Request DeleteStream
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy DeleteStream
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DeleteStream)))
response = AWSResponse DeleteStream
-> Logger
-> Service
-> Proxy DeleteStream
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DeleteStream)))
forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull AWSResponse DeleteStream
DeleteStreamResponse
DeleteStreamResponse'

instance Prelude.Hashable DeleteStream

instance Prelude.NFData DeleteStream

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

instance Core.ToJSON DeleteStream where
  toJSON :: DeleteStream -> Value
toJSON DeleteStream' {Maybe Bool
Text
streamName :: Text
enforceConsumerDeletion :: Maybe Bool
$sel:streamName:DeleteStream' :: DeleteStream -> Text
$sel:enforceConsumerDeletion:DeleteStream' :: DeleteStream -> Maybe Bool
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"EnforceConsumerDeletion" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
enforceConsumerDeletion,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"StreamName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
streamName)
          ]
      )

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

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

-- | /See:/ 'newDeleteStreamResponse' smart constructor.
data DeleteStreamResponse = DeleteStreamResponse'
  {
  }
  deriving (DeleteStreamResponse -> DeleteStreamResponse -> Bool
(DeleteStreamResponse -> DeleteStreamResponse -> Bool)
-> (DeleteStreamResponse -> DeleteStreamResponse -> Bool)
-> Eq DeleteStreamResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeleteStreamResponse -> DeleteStreamResponse -> Bool
$c/= :: DeleteStreamResponse -> DeleteStreamResponse -> Bool
== :: DeleteStreamResponse -> DeleteStreamResponse -> Bool
$c== :: DeleteStreamResponse -> DeleteStreamResponse -> Bool
Prelude.Eq, ReadPrec [DeleteStreamResponse]
ReadPrec DeleteStreamResponse
Int -> ReadS DeleteStreamResponse
ReadS [DeleteStreamResponse]
(Int -> ReadS DeleteStreamResponse)
-> ReadS [DeleteStreamResponse]
-> ReadPrec DeleteStreamResponse
-> ReadPrec [DeleteStreamResponse]
-> Read DeleteStreamResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeleteStreamResponse]
$creadListPrec :: ReadPrec [DeleteStreamResponse]
readPrec :: ReadPrec DeleteStreamResponse
$creadPrec :: ReadPrec DeleteStreamResponse
readList :: ReadS [DeleteStreamResponse]
$creadList :: ReadS [DeleteStreamResponse]
readsPrec :: Int -> ReadS DeleteStreamResponse
$creadsPrec :: Int -> ReadS DeleteStreamResponse
Prelude.Read, Int -> DeleteStreamResponse -> ShowS
[DeleteStreamResponse] -> ShowS
DeleteStreamResponse -> String
(Int -> DeleteStreamResponse -> ShowS)
-> (DeleteStreamResponse -> String)
-> ([DeleteStreamResponse] -> ShowS)
-> Show DeleteStreamResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteStreamResponse] -> ShowS
$cshowList :: [DeleteStreamResponse] -> ShowS
show :: DeleteStreamResponse -> String
$cshow :: DeleteStreamResponse -> String
showsPrec :: Int -> DeleteStreamResponse -> ShowS
$cshowsPrec :: Int -> DeleteStreamResponse -> ShowS
Prelude.Show, (forall x. DeleteStreamResponse -> Rep DeleteStreamResponse x)
-> (forall x. Rep DeleteStreamResponse x -> DeleteStreamResponse)
-> Generic DeleteStreamResponse
forall x. Rep DeleteStreamResponse x -> DeleteStreamResponse
forall x. DeleteStreamResponse -> Rep DeleteStreamResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeleteStreamResponse x -> DeleteStreamResponse
$cfrom :: forall x. DeleteStreamResponse -> Rep DeleteStreamResponse x
Prelude.Generic)

-- |
-- Create a value of 'DeleteStreamResponse' 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.
newDeleteStreamResponse ::
  DeleteStreamResponse
newDeleteStreamResponse :: DeleteStreamResponse
newDeleteStreamResponse = DeleteStreamResponse
DeleteStreamResponse'

instance Prelude.NFData DeleteStreamResponse