{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}

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

-- |
-- Module      : Amazonka.DynamoDB.Waiters
-- 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)
module Amazonka.DynamoDB.Waiters where

import qualified Amazonka.Core as Core
import Amazonka.DynamoDB.DescribeTable
import Amazonka.DynamoDB.Lens
import Amazonka.DynamoDB.Types
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Polls 'Amazonka.DynamoDB.DescribeTable' every 20 seconds until a successful state is reached. An error is returned after 25 failed checks.
newTableNotExists :: Core.Wait DescribeTable
newTableNotExists :: Wait DescribeTable
newTableNotExists =
  Wait :: forall a. ByteString -> Int -> Seconds -> [Acceptor a] -> Wait a
Core.Wait
    { $sel:_waitName:Wait :: ByteString
Core._waitName = ByteString
"TableNotExists",
      $sel:_waitAttempts:Wait :: Int
Core._waitAttempts = Int
25,
      $sel:_waitDelay:Wait :: Seconds
Core._waitDelay = Seconds
20,
      $sel:_waitAcceptors:Wait :: [Acceptor DescribeTable]
Core._waitAcceptors =
        [ ErrorCode -> Accept -> Acceptor DescribeTable
forall a. ErrorCode -> Accept -> Acceptor a
Core.matchError
            ErrorCode
"ResourceNotFoundException"
            Accept
Core.AcceptSuccess
        ]
    }

-- | Polls 'Amazonka.DynamoDB.DescribeTable' every 20 seconds until a successful state is reached. An error is returned after 25 failed checks.
newTableExists :: Core.Wait DescribeTable
newTableExists :: Wait DescribeTable
newTableExists =
  Wait :: forall a. ByteString -> Int -> Seconds -> [Acceptor a] -> Wait a
Core.Wait
    { $sel:_waitName:Wait :: ByteString
Core._waitName = ByteString
"TableExists",
      $sel:_waitAttempts:Wait :: Int
Core._waitAttempts = Int
25,
      $sel:_waitDelay:Wait :: Seconds
Core._waitDelay = Seconds
20,
      $sel:_waitAcceptors:Wait :: [Acceptor DescribeTable]
Core._waitAcceptors =
        [ CI Text
-> Accept
-> Fold (AWSResponse DescribeTable) (CI Text)
-> Acceptor DescribeTable
forall b a.
Eq b =>
b -> Accept -> Fold (AWSResponse a) b -> Acceptor a
Core.matchAll
            CI Text
"ACTIVE"
            Accept
Core.AcceptSuccess
            ( (Maybe TableDescription -> f (Maybe TableDescription))
-> DescribeTableResponse -> f DescribeTableResponse
Lens' DescribeTableResponse (Maybe TableDescription)
describeTableResponse_table ((Maybe TableDescription -> f (Maybe TableDescription))
 -> DescribeTableResponse -> f DescribeTableResponse)
-> ((CI Text -> f (CI Text))
    -> Maybe TableDescription -> f (Maybe TableDescription))
-> (CI Text -> f (CI Text))
-> DescribeTableResponse
-> f DescribeTableResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (TableDescription -> f TableDescription)
-> Maybe TableDescription -> f (Maybe TableDescription)
forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just
                ((TableDescription -> f TableDescription)
 -> Maybe TableDescription -> f (Maybe TableDescription))
-> ((CI Text -> f (CI Text))
    -> TableDescription -> f TableDescription)
-> (CI Text -> f (CI Text))
-> Maybe TableDescription
-> f (Maybe TableDescription)
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (Maybe TableStatus -> f (Maybe TableStatus))
-> TableDescription -> f TableDescription
Lens' TableDescription (Maybe TableStatus)
tableDescription_tableStatus
                ((Maybe TableStatus -> f (Maybe TableStatus))
 -> TableDescription -> f TableDescription)
-> ((CI Text -> f (CI Text))
    -> Maybe TableStatus -> f (Maybe TableStatus))
-> (CI Text -> f (CI Text))
-> TableDescription
-> f TableDescription
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (TableStatus -> f TableStatus)
-> Maybe TableStatus -> f (Maybe TableStatus)
forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just
                ((TableStatus -> f TableStatus)
 -> Maybe TableStatus -> f (Maybe TableStatus))
-> ((CI Text -> f (CI Text)) -> TableStatus -> f TableStatus)
-> (CI Text -> f (CI Text))
-> Maybe TableStatus
-> f (Maybe TableStatus)
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (TableStatus -> CI Text)
-> (CI Text -> f (CI Text)) -> TableStatus -> f TableStatus
forall (p :: * -> * -> *) (f :: * -> *) s a.
(Profunctor p, Contravariant f) =>
(s -> a) -> Optic' p f s a
Lens.to TableStatus -> CI Text
forall a. ToText a => a -> CI Text
Core.toTextCI
            ),
          ErrorCode -> Accept -> Acceptor DescribeTable
forall a. ErrorCode -> Accept -> Acceptor a
Core.matchError
            ErrorCode
"ResourceNotFoundException"
            Accept
Core.AcceptRetry
        ]
    }