{-# 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.DynamoDB.DeleteTable
-- 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)
--
-- The @DeleteTable@ operation deletes a table and all of its items. After
-- a @DeleteTable@ request, the specified table is in the @DELETING@ state
-- until DynamoDB completes the deletion. If the table is in the @ACTIVE@
-- state, you can delete it. If a table is in @CREATING@ or @UPDATING@
-- states, then DynamoDB returns a @ResourceInUseException@. If the
-- specified table does not exist, DynamoDB returns a
-- @ResourceNotFoundException@. If table is already in the @DELETING@
-- state, no error is returned.
--
-- DynamoDB might continue to accept data read and write operations, such
-- as @GetItem@ and @PutItem@, on a table in the @DELETING@ state until the
-- table deletion is complete.
--
-- When you delete a table, any indexes on that table are also deleted.
--
-- If you have DynamoDB Streams enabled on the table, then the
-- corresponding stream on that table goes into the @DISABLED@ state, and
-- the stream is automatically deleted after 24 hours.
--
-- Use the @DescribeTable@ action to check the status of the table.
module Amazonka.DynamoDB.DeleteTable
  ( -- * Creating a Request
    DeleteTable (..),
    newDeleteTable,

    -- * Request Lenses
    deleteTable_tableName,

    -- * Destructuring the Response
    DeleteTableResponse (..),
    newDeleteTableResponse,

    -- * Response Lenses
    deleteTableResponse_tableDescription,
    deleteTableResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.DynamoDB.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 @DeleteTable@ operation.
--
-- /See:/ 'newDeleteTable' smart constructor.
data DeleteTable = DeleteTable'
  { -- | The name of the table to delete.
    DeleteTable -> Text
tableName :: Prelude.Text
  }
  deriving (DeleteTable -> DeleteTable -> Bool
(DeleteTable -> DeleteTable -> Bool)
-> (DeleteTable -> DeleteTable -> Bool) -> Eq DeleteTable
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeleteTable -> DeleteTable -> Bool
$c/= :: DeleteTable -> DeleteTable -> Bool
== :: DeleteTable -> DeleteTable -> Bool
$c== :: DeleteTable -> DeleteTable -> Bool
Prelude.Eq, ReadPrec [DeleteTable]
ReadPrec DeleteTable
Int -> ReadS DeleteTable
ReadS [DeleteTable]
(Int -> ReadS DeleteTable)
-> ReadS [DeleteTable]
-> ReadPrec DeleteTable
-> ReadPrec [DeleteTable]
-> Read DeleteTable
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeleteTable]
$creadListPrec :: ReadPrec [DeleteTable]
readPrec :: ReadPrec DeleteTable
$creadPrec :: ReadPrec DeleteTable
readList :: ReadS [DeleteTable]
$creadList :: ReadS [DeleteTable]
readsPrec :: Int -> ReadS DeleteTable
$creadsPrec :: Int -> ReadS DeleteTable
Prelude.Read, Int -> DeleteTable -> ShowS
[DeleteTable] -> ShowS
DeleteTable -> String
(Int -> DeleteTable -> ShowS)
-> (DeleteTable -> String)
-> ([DeleteTable] -> ShowS)
-> Show DeleteTable
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteTable] -> ShowS
$cshowList :: [DeleteTable] -> ShowS
show :: DeleteTable -> String
$cshow :: DeleteTable -> String
showsPrec :: Int -> DeleteTable -> ShowS
$cshowsPrec :: Int -> DeleteTable -> ShowS
Prelude.Show, (forall x. DeleteTable -> Rep DeleteTable x)
-> (forall x. Rep DeleteTable x -> DeleteTable)
-> Generic DeleteTable
forall x. Rep DeleteTable x -> DeleteTable
forall x. DeleteTable -> Rep DeleteTable x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeleteTable x -> DeleteTable
$cfrom :: forall x. DeleteTable -> Rep DeleteTable x
Prelude.Generic)

-- |
-- Create a value of 'DeleteTable' 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:
--
-- 'tableName', 'deleteTable_tableName' - The name of the table to delete.
newDeleteTable ::
  -- | 'tableName'
  Prelude.Text ->
  DeleteTable
newDeleteTable :: Text -> DeleteTable
newDeleteTable Text
pTableName_ =
  DeleteTable' :: Text -> DeleteTable
DeleteTable' {$sel:tableName:DeleteTable' :: Text
tableName = Text
pTableName_}

-- | The name of the table to delete.
deleteTable_tableName :: Lens.Lens' DeleteTable Prelude.Text
deleteTable_tableName :: (Text -> f Text) -> DeleteTable -> f DeleteTable
deleteTable_tableName = (DeleteTable -> Text)
-> (DeleteTable -> Text -> DeleteTable)
-> Lens DeleteTable DeleteTable Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteTable' {Text
tableName :: Text
$sel:tableName:DeleteTable' :: DeleteTable -> Text
tableName} -> Text
tableName) (\s :: DeleteTable
s@DeleteTable' {} Text
a -> DeleteTable
s {$sel:tableName:DeleteTable' :: Text
tableName = Text
a} :: DeleteTable)

instance Core.AWSRequest DeleteTable where
  type AWSResponse DeleteTable = DeleteTableResponse
  request :: DeleteTable -> Request DeleteTable
request = Service -> DeleteTable -> Request DeleteTable
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy DeleteTable
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DeleteTable)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse DeleteTable))
-> Logger
-> Service
-> Proxy DeleteTable
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DeleteTable)))
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 TableDescription -> Int -> DeleteTableResponse
DeleteTableResponse'
            (Maybe TableDescription -> Int -> DeleteTableResponse)
-> Either String (Maybe TableDescription)
-> Either String (Int -> DeleteTableResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe TableDescription)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"TableDescription")
            Either String (Int -> DeleteTableResponse)
-> Either String Int -> Either String DeleteTableResponse
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 DeleteTable

instance Prelude.NFData DeleteTable

instance Core.ToHeaders DeleteTable where
  toHeaders :: DeleteTable -> ResponseHeaders
toHeaders =
    ResponseHeaders -> DeleteTable -> 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
"DynamoDB_20120810.DeleteTable" ::
                          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 DeleteTable where
  toJSON :: DeleteTable -> Value
toJSON DeleteTable' {Text
tableName :: Text
$sel:tableName:DeleteTable' :: DeleteTable -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"TableName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
tableName)]
      )

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

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

-- | Represents the output of a @DeleteTable@ operation.
--
-- /See:/ 'newDeleteTableResponse' smart constructor.
data DeleteTableResponse = DeleteTableResponse'
  { -- | Represents the properties of a table.
    DeleteTableResponse -> Maybe TableDescription
tableDescription :: Prelude.Maybe TableDescription,
    -- | The response's http status code.
    DeleteTableResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (DeleteTableResponse -> DeleteTableResponse -> Bool
(DeleteTableResponse -> DeleteTableResponse -> Bool)
-> (DeleteTableResponse -> DeleteTableResponse -> Bool)
-> Eq DeleteTableResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeleteTableResponse -> DeleteTableResponse -> Bool
$c/= :: DeleteTableResponse -> DeleteTableResponse -> Bool
== :: DeleteTableResponse -> DeleteTableResponse -> Bool
$c== :: DeleteTableResponse -> DeleteTableResponse -> Bool
Prelude.Eq, ReadPrec [DeleteTableResponse]
ReadPrec DeleteTableResponse
Int -> ReadS DeleteTableResponse
ReadS [DeleteTableResponse]
(Int -> ReadS DeleteTableResponse)
-> ReadS [DeleteTableResponse]
-> ReadPrec DeleteTableResponse
-> ReadPrec [DeleteTableResponse]
-> Read DeleteTableResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeleteTableResponse]
$creadListPrec :: ReadPrec [DeleteTableResponse]
readPrec :: ReadPrec DeleteTableResponse
$creadPrec :: ReadPrec DeleteTableResponse
readList :: ReadS [DeleteTableResponse]
$creadList :: ReadS [DeleteTableResponse]
readsPrec :: Int -> ReadS DeleteTableResponse
$creadsPrec :: Int -> ReadS DeleteTableResponse
Prelude.Read, Int -> DeleteTableResponse -> ShowS
[DeleteTableResponse] -> ShowS
DeleteTableResponse -> String
(Int -> DeleteTableResponse -> ShowS)
-> (DeleteTableResponse -> String)
-> ([DeleteTableResponse] -> ShowS)
-> Show DeleteTableResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteTableResponse] -> ShowS
$cshowList :: [DeleteTableResponse] -> ShowS
show :: DeleteTableResponse -> String
$cshow :: DeleteTableResponse -> String
showsPrec :: Int -> DeleteTableResponse -> ShowS
$cshowsPrec :: Int -> DeleteTableResponse -> ShowS
Prelude.Show, (forall x. DeleteTableResponse -> Rep DeleteTableResponse x)
-> (forall x. Rep DeleteTableResponse x -> DeleteTableResponse)
-> Generic DeleteTableResponse
forall x. Rep DeleteTableResponse x -> DeleteTableResponse
forall x. DeleteTableResponse -> Rep DeleteTableResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeleteTableResponse x -> DeleteTableResponse
$cfrom :: forall x. DeleteTableResponse -> Rep DeleteTableResponse x
Prelude.Generic)

-- |
-- Create a value of 'DeleteTableResponse' 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:
--
-- 'tableDescription', 'deleteTableResponse_tableDescription' - Represents the properties of a table.
--
-- 'httpStatus', 'deleteTableResponse_httpStatus' - The response's http status code.
newDeleteTableResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DeleteTableResponse
newDeleteTableResponse :: Int -> DeleteTableResponse
newDeleteTableResponse Int
pHttpStatus_ =
  DeleteTableResponse' :: Maybe TableDescription -> Int -> DeleteTableResponse
DeleteTableResponse'
    { $sel:tableDescription:DeleteTableResponse' :: Maybe TableDescription
tableDescription =
        Maybe TableDescription
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DeleteTableResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Represents the properties of a table.
deleteTableResponse_tableDescription :: Lens.Lens' DeleteTableResponse (Prelude.Maybe TableDescription)
deleteTableResponse_tableDescription :: (Maybe TableDescription -> f (Maybe TableDescription))
-> DeleteTableResponse -> f DeleteTableResponse
deleteTableResponse_tableDescription = (DeleteTableResponse -> Maybe TableDescription)
-> (DeleteTableResponse
    -> Maybe TableDescription -> DeleteTableResponse)
-> Lens
     DeleteTableResponse
     DeleteTableResponse
     (Maybe TableDescription)
     (Maybe TableDescription)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteTableResponse' {Maybe TableDescription
tableDescription :: Maybe TableDescription
$sel:tableDescription:DeleteTableResponse' :: DeleteTableResponse -> Maybe TableDescription
tableDescription} -> Maybe TableDescription
tableDescription) (\s :: DeleteTableResponse
s@DeleteTableResponse' {} Maybe TableDescription
a -> DeleteTableResponse
s {$sel:tableDescription:DeleteTableResponse' :: Maybe TableDescription
tableDescription = Maybe TableDescription
a} :: DeleteTableResponse)

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

instance Prelude.NFData DeleteTableResponse