{-# 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.CloudControl.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.CloudControl.Waiters where

import Amazonka.CloudControl.GetResourceRequestStatus
import Amazonka.CloudControl.Lens
import Amazonka.CloudControl.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Polls 'Amazonka.CloudControl.GetResourceRequestStatus' every 5 seconds until a successful state is reached. An error is returned after 720 failed checks.
newResourceRequestSuccess :: Core.Wait GetResourceRequestStatus
newResourceRequestSuccess :: Wait GetResourceRequestStatus
newResourceRequestSuccess =
  Wait :: forall a. ByteString -> Int -> Seconds -> [Acceptor a] -> Wait a
Core.Wait
    { $sel:_waitName:Wait :: ByteString
Core._waitName =
        ByteString
"ResourceRequestSuccess",
      $sel:_waitAttempts:Wait :: Int
Core._waitAttempts = Int
720,
      $sel:_waitDelay:Wait :: Seconds
Core._waitDelay = Seconds
5,
      $sel:_waitAcceptors:Wait :: [Acceptor GetResourceRequestStatus]
Core._waitAcceptors =
        [ CI Text
-> Accept
-> Fold (AWSResponse GetResourceRequestStatus) (CI Text)
-> Acceptor GetResourceRequestStatus
forall b a.
Eq b =>
b -> Accept -> Fold (AWSResponse a) b -> Acceptor a
Core.matchAll
            CI Text
"SUCCESS"
            Accept
Core.AcceptSuccess
            ( (Maybe ProgressEvent -> f (Maybe ProgressEvent))
-> GetResourceRequestStatusResponse
-> f GetResourceRequestStatusResponse
Lens' GetResourceRequestStatusResponse (Maybe ProgressEvent)
getResourceRequestStatusResponse_progressEvent
                ((Maybe ProgressEvent -> f (Maybe ProgressEvent))
 -> GetResourceRequestStatusResponse
 -> f GetResourceRequestStatusResponse)
-> ((CI Text -> f (CI Text))
    -> Maybe ProgressEvent -> f (Maybe ProgressEvent))
-> (CI Text -> f (CI Text))
-> GetResourceRequestStatusResponse
-> f GetResourceRequestStatusResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (ProgressEvent -> f ProgressEvent)
-> Maybe ProgressEvent -> f (Maybe ProgressEvent)
forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just
                ((ProgressEvent -> f ProgressEvent)
 -> Maybe ProgressEvent -> f (Maybe ProgressEvent))
-> ((CI Text -> f (CI Text)) -> ProgressEvent -> f ProgressEvent)
-> (CI Text -> f (CI Text))
-> Maybe ProgressEvent
-> f (Maybe ProgressEvent)
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (Maybe OperationStatus -> f (Maybe OperationStatus))
-> ProgressEvent -> f ProgressEvent
Lens' ProgressEvent (Maybe OperationStatus)
progressEvent_operationStatus
                ((Maybe OperationStatus -> f (Maybe OperationStatus))
 -> ProgressEvent -> f ProgressEvent)
-> ((CI Text -> f (CI Text))
    -> Maybe OperationStatus -> f (Maybe OperationStatus))
-> (CI Text -> f (CI Text))
-> ProgressEvent
-> f ProgressEvent
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (OperationStatus -> f OperationStatus)
-> Maybe OperationStatus -> f (Maybe OperationStatus)
forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just
                ((OperationStatus -> f OperationStatus)
 -> Maybe OperationStatus -> f (Maybe OperationStatus))
-> ((CI Text -> f (CI Text))
    -> OperationStatus -> f OperationStatus)
-> (CI Text -> f (CI Text))
-> Maybe OperationStatus
-> f (Maybe OperationStatus)
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (OperationStatus -> CI Text)
-> (CI Text -> f (CI Text)) -> OperationStatus -> f OperationStatus
forall (p :: * -> * -> *) (f :: * -> *) s a.
(Profunctor p, Contravariant f) =>
(s -> a) -> Optic' p f s a
Lens.to OperationStatus -> CI Text
forall a. ToText a => a -> CI Text
Core.toTextCI
            ),
          CI Text
-> Accept
-> Fold (AWSResponse GetResourceRequestStatus) (CI Text)
-> Acceptor GetResourceRequestStatus
forall b a.
Eq b =>
b -> Accept -> Fold (AWSResponse a) b -> Acceptor a
Core.matchAll
            CI Text
"FAILED"
            Accept
Core.AcceptFailure
            ( (Maybe ProgressEvent -> f (Maybe ProgressEvent))
-> GetResourceRequestStatusResponse
-> f GetResourceRequestStatusResponse
Lens' GetResourceRequestStatusResponse (Maybe ProgressEvent)
getResourceRequestStatusResponse_progressEvent
                ((Maybe ProgressEvent -> f (Maybe ProgressEvent))
 -> GetResourceRequestStatusResponse
 -> f GetResourceRequestStatusResponse)
-> ((CI Text -> f (CI Text))
    -> Maybe ProgressEvent -> f (Maybe ProgressEvent))
-> (CI Text -> f (CI Text))
-> GetResourceRequestStatusResponse
-> f GetResourceRequestStatusResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (ProgressEvent -> f ProgressEvent)
-> Maybe ProgressEvent -> f (Maybe ProgressEvent)
forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just
                ((ProgressEvent -> f ProgressEvent)
 -> Maybe ProgressEvent -> f (Maybe ProgressEvent))
-> ((CI Text -> f (CI Text)) -> ProgressEvent -> f ProgressEvent)
-> (CI Text -> f (CI Text))
-> Maybe ProgressEvent
-> f (Maybe ProgressEvent)
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (Maybe OperationStatus -> f (Maybe OperationStatus))
-> ProgressEvent -> f ProgressEvent
Lens' ProgressEvent (Maybe OperationStatus)
progressEvent_operationStatus
                ((Maybe OperationStatus -> f (Maybe OperationStatus))
 -> ProgressEvent -> f ProgressEvent)
-> ((CI Text -> f (CI Text))
    -> Maybe OperationStatus -> f (Maybe OperationStatus))
-> (CI Text -> f (CI Text))
-> ProgressEvent
-> f ProgressEvent
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (OperationStatus -> f OperationStatus)
-> Maybe OperationStatus -> f (Maybe OperationStatus)
forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just
                ((OperationStatus -> f OperationStatus)
 -> Maybe OperationStatus -> f (Maybe OperationStatus))
-> ((CI Text -> f (CI Text))
    -> OperationStatus -> f OperationStatus)
-> (CI Text -> f (CI Text))
-> Maybe OperationStatus
-> f (Maybe OperationStatus)
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (OperationStatus -> CI Text)
-> (CI Text -> f (CI Text)) -> OperationStatus -> f OperationStatus
forall (p :: * -> * -> *) (f :: * -> *) s a.
(Profunctor p, Contravariant f) =>
(s -> a) -> Optic' p f s a
Lens.to OperationStatus -> CI Text
forall a. ToText a => a -> CI Text
Core.toTextCI
            ),
          CI Text
-> Accept
-> Fold (AWSResponse GetResourceRequestStatus) (CI Text)
-> Acceptor GetResourceRequestStatus
forall b a.
Eq b =>
b -> Accept -> Fold (AWSResponse a) b -> Acceptor a
Core.matchAll
            CI Text
"CANCEL_COMPLETE"
            Accept
Core.AcceptFailure
            ( (Maybe ProgressEvent -> f (Maybe ProgressEvent))
-> GetResourceRequestStatusResponse
-> f GetResourceRequestStatusResponse
Lens' GetResourceRequestStatusResponse (Maybe ProgressEvent)
getResourceRequestStatusResponse_progressEvent
                ((Maybe ProgressEvent -> f (Maybe ProgressEvent))
 -> GetResourceRequestStatusResponse
 -> f GetResourceRequestStatusResponse)
-> ((CI Text -> f (CI Text))
    -> Maybe ProgressEvent -> f (Maybe ProgressEvent))
-> (CI Text -> f (CI Text))
-> GetResourceRequestStatusResponse
-> f GetResourceRequestStatusResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (ProgressEvent -> f ProgressEvent)
-> Maybe ProgressEvent -> f (Maybe ProgressEvent)
forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just
                ((ProgressEvent -> f ProgressEvent)
 -> Maybe ProgressEvent -> f (Maybe ProgressEvent))
-> ((CI Text -> f (CI Text)) -> ProgressEvent -> f ProgressEvent)
-> (CI Text -> f (CI Text))
-> Maybe ProgressEvent
-> f (Maybe ProgressEvent)
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (Maybe OperationStatus -> f (Maybe OperationStatus))
-> ProgressEvent -> f ProgressEvent
Lens' ProgressEvent (Maybe OperationStatus)
progressEvent_operationStatus
                ((Maybe OperationStatus -> f (Maybe OperationStatus))
 -> ProgressEvent -> f ProgressEvent)
-> ((CI Text -> f (CI Text))
    -> Maybe OperationStatus -> f (Maybe OperationStatus))
-> (CI Text -> f (CI Text))
-> ProgressEvent
-> f ProgressEvent
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (OperationStatus -> f OperationStatus)
-> Maybe OperationStatus -> f (Maybe OperationStatus)
forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just
                ((OperationStatus -> f OperationStatus)
 -> Maybe OperationStatus -> f (Maybe OperationStatus))
-> ((CI Text -> f (CI Text))
    -> OperationStatus -> f OperationStatus)
-> (CI Text -> f (CI Text))
-> Maybe OperationStatus
-> f (Maybe OperationStatus)
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (OperationStatus -> CI Text)
-> (CI Text -> f (CI Text)) -> OperationStatus -> f OperationStatus
forall (p :: * -> * -> *) (f :: * -> *) s a.
(Profunctor p, Contravariant f) =>
(s -> a) -> Optic' p f s a
Lens.to OperationStatus -> CI Text
forall a. ToText a => a -> CI Text
Core.toTextCI
            )
        ]
    }