{-# 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.DescribeTable
-- 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 the table, including the current status of the
-- table, when it was created, the primary key schema, and any indexes on
-- the table.
--
-- If you issue a @DescribeTable@ request immediately after a @CreateTable@
-- request, DynamoDB might return a @ResourceNotFoundException@. This is
-- because @DescribeTable@ uses an eventually consistent query, and the
-- metadata for your table might not be available at that moment. Wait for
-- a few seconds, and then try the @DescribeTable@ request again.
module Amazonka.DynamoDB.DescribeTable
  ( -- * Creating a Request
    DescribeTable (..),
    newDescribeTable,

    -- * Request Lenses
    describeTable_tableName,

    -- * Destructuring the Response
    DescribeTableResponse (..),
    newDescribeTableResponse,

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

-- |
-- Create a value of 'DescribeTable' 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', 'describeTable_tableName' - The name of the table to describe.
newDescribeTable ::
  -- | 'tableName'
  Prelude.Text ->
  DescribeTable
newDescribeTable :: Text -> DescribeTable
newDescribeTable Text
pTableName_ =
  DescribeTable' :: Text -> DescribeTable
DescribeTable' {$sel:tableName:DescribeTable' :: Text
tableName = Text
pTableName_}

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

instance Core.AWSRequest DescribeTable where
  type
    AWSResponse DescribeTable =
      DescribeTableResponse
  request :: DescribeTable -> Request DescribeTable
request = Service -> DescribeTable -> Request DescribeTable
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy DescribeTable
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DescribeTable)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse DescribeTable))
-> Logger
-> Service
-> Proxy DescribeTable
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DescribeTable)))
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 -> DescribeTableResponse
DescribeTableResponse'
            (Maybe TableDescription -> Int -> DescribeTableResponse)
-> Either String (Maybe TableDescription)
-> Either String (Int -> DescribeTableResponse)
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
"Table")
            Either String (Int -> DescribeTableResponse)
-> Either String Int -> Either String DescribeTableResponse
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 DescribeTable

instance Prelude.NFData DescribeTable

instance Core.ToHeaders DescribeTable where
  toHeaders :: DescribeTable -> ResponseHeaders
toHeaders =
    ResponseHeaders -> DescribeTable -> 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.DescribeTable" ::
                          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 DescribeTable where
  toJSON :: DescribeTable -> Value
toJSON DescribeTable' {Text
tableName :: Text
$sel:tableName:DescribeTable' :: DescribeTable -> 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 DescribeTable where
  toPath :: DescribeTable -> ByteString
toPath = ByteString -> DescribeTable -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

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

-- |
-- Create a value of 'DescribeTableResponse' 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:
--
-- 'table', 'describeTableResponse_table' - The properties of the table.
--
-- 'httpStatus', 'describeTableResponse_httpStatus' - The response's http status code.
newDescribeTableResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DescribeTableResponse
newDescribeTableResponse :: Int -> DescribeTableResponse
newDescribeTableResponse Int
pHttpStatus_ =
  DescribeTableResponse' :: Maybe TableDescription -> Int -> DescribeTableResponse
DescribeTableResponse'
    { $sel:table:DescribeTableResponse' :: Maybe TableDescription
table = Maybe TableDescription
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DescribeTableResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

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

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

instance Prelude.NFData DescribeTableResponse