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

import Amazonka.CloudWatch.DescribeAlarms
import Amazonka.CloudWatch.Lens
import Amazonka.CloudWatch.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Polls 'Amazonka.CloudWatch.DescribeAlarms' every 5 seconds until a successful state is reached. An error is returned after 40 failed checks.
newCompositeAlarmExists :: Core.Wait DescribeAlarms
newCompositeAlarmExists :: Wait DescribeAlarms
newCompositeAlarmExists =
  Wait :: forall a. ByteString -> Int -> Seconds -> [Acceptor a] -> Wait a
Core.Wait
    { $sel:_waitName:Wait :: ByteString
Core._waitName = ByteString
"CompositeAlarmExists",
      $sel:_waitAttempts:Wait :: Int
Core._waitAttempts = Int
40,
      $sel:_waitDelay:Wait :: Seconds
Core._waitDelay = Seconds
5,
      $sel:_waitAcceptors:Wait :: [Acceptor DescribeAlarms]
Core._waitAcceptors =
        [ Bool
-> Accept
-> Fold (AWSResponse DescribeAlarms) CompositeAlarm
-> Acceptor DescribeAlarms
forall a b. Bool -> Accept -> Fold (AWSResponse a) b -> Acceptor a
Core.matchNonEmpty
            Bool
Prelude.True
            Accept
Core.AcceptSuccess
            ( (DescribeAlarmsResponse -> [CompositeAlarm])
-> Fold DescribeAlarmsResponse CompositeAlarm
forall (f :: * -> *) s a. Foldable f => (s -> f a) -> Fold s a
Lens.folding
                ( Getting [CompositeAlarm] DescribeAlarmsResponse [CompositeAlarm]
-> DescribeAlarmsResponse -> [CompositeAlarm]
forall r s. Getting [r] s [r] -> s -> [r]
Lens.concatOf
                    ( (Maybe [CompositeAlarm]
 -> Const [CompositeAlarm] (Maybe [CompositeAlarm]))
-> DescribeAlarmsResponse
-> Const [CompositeAlarm] DescribeAlarmsResponse
Lens' DescribeAlarmsResponse (Maybe [CompositeAlarm])
describeAlarmsResponse_compositeAlarms
                        ((Maybe [CompositeAlarm]
  -> Const [CompositeAlarm] (Maybe [CompositeAlarm]))
 -> DescribeAlarmsResponse
 -> Const [CompositeAlarm] DescribeAlarmsResponse)
-> (([CompositeAlarm] -> Const [CompositeAlarm] [CompositeAlarm])
    -> Maybe [CompositeAlarm]
    -> Const [CompositeAlarm] (Maybe [CompositeAlarm]))
-> Getting [CompositeAlarm] DescribeAlarmsResponse [CompositeAlarm]
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([CompositeAlarm] -> Const [CompositeAlarm] [CompositeAlarm])
-> Maybe [CompositeAlarm]
-> Const [CompositeAlarm] (Maybe [CompositeAlarm])
forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just
                    )
                )
            )
        ]
    }

-- | Polls 'Amazonka.CloudWatch.DescribeAlarms' every 5 seconds until a successful state is reached. An error is returned after 40 failed checks.
newAlarmExists :: Core.Wait DescribeAlarms
newAlarmExists :: Wait DescribeAlarms
newAlarmExists =
  Wait :: forall a. ByteString -> Int -> Seconds -> [Acceptor a] -> Wait a
Core.Wait
    { $sel:_waitName:Wait :: ByteString
Core._waitName = ByteString
"AlarmExists",
      $sel:_waitAttempts:Wait :: Int
Core._waitAttempts = Int
40,
      $sel:_waitDelay:Wait :: Seconds
Core._waitDelay = Seconds
5,
      $sel:_waitAcceptors:Wait :: [Acceptor DescribeAlarms]
Core._waitAcceptors =
        [ Bool
-> Accept
-> Fold (AWSResponse DescribeAlarms) MetricAlarm
-> Acceptor DescribeAlarms
forall a b. Bool -> Accept -> Fold (AWSResponse a) b -> Acceptor a
Core.matchNonEmpty
            Bool
Prelude.True
            Accept
Core.AcceptSuccess
            ( (DescribeAlarmsResponse -> [MetricAlarm])
-> Fold DescribeAlarmsResponse MetricAlarm
forall (f :: * -> *) s a. Foldable f => (s -> f a) -> Fold s a
Lens.folding
                ( Getting [MetricAlarm] DescribeAlarmsResponse [MetricAlarm]
-> DescribeAlarmsResponse -> [MetricAlarm]
forall r s. Getting [r] s [r] -> s -> [r]
Lens.concatOf
                    ( (Maybe [MetricAlarm] -> Const [MetricAlarm] (Maybe [MetricAlarm]))
-> DescribeAlarmsResponse
-> Const [MetricAlarm] DescribeAlarmsResponse
Lens' DescribeAlarmsResponse (Maybe [MetricAlarm])
describeAlarmsResponse_metricAlarms
                        ((Maybe [MetricAlarm] -> Const [MetricAlarm] (Maybe [MetricAlarm]))
 -> DescribeAlarmsResponse
 -> Const [MetricAlarm] DescribeAlarmsResponse)
-> (([MetricAlarm] -> Const [MetricAlarm] [MetricAlarm])
    -> Maybe [MetricAlarm]
    -> Const [MetricAlarm] (Maybe [MetricAlarm]))
-> Getting [MetricAlarm] DescribeAlarmsResponse [MetricAlarm]
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([MetricAlarm] -> Const [MetricAlarm] [MetricAlarm])
-> Maybe [MetricAlarm] -> Const [MetricAlarm] (Maybe [MetricAlarm])
forall a b. Prism (Maybe a) (Maybe b) a b
Lens._Just
                    )
                )
            )
        ]
    }