{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

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

-- |
-- Module      : Amazonka.CloudWatchEvents.Types.RetryPolicy
-- 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.CloudWatchEvents.Types.RetryPolicy where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A @RetryPolicy@ object that includes information about the retry policy
-- settings.
--
-- /See:/ 'newRetryPolicy' smart constructor.
data RetryPolicy = RetryPolicy'
  { -- | The maximum amount of time, in seconds, to continue to make retry
    -- attempts.
    RetryPolicy -> Maybe Natural
maximumEventAgeInSeconds :: Prelude.Maybe Prelude.Natural,
    -- | The maximum number of retry attempts to make before the request fails.
    -- Retry attempts continue until either the maximum number of attempts is
    -- made or until the duration of the @MaximumEventAgeInSeconds@ is met.
    RetryPolicy -> Maybe Natural
maximumRetryAttempts :: Prelude.Maybe Prelude.Natural
  }
  deriving (RetryPolicy -> RetryPolicy -> Bool
(RetryPolicy -> RetryPolicy -> Bool)
-> (RetryPolicy -> RetryPolicy -> Bool) -> Eq RetryPolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RetryPolicy -> RetryPolicy -> Bool
$c/= :: RetryPolicy -> RetryPolicy -> Bool
== :: RetryPolicy -> RetryPolicy -> Bool
$c== :: RetryPolicy -> RetryPolicy -> Bool
Prelude.Eq, ReadPrec [RetryPolicy]
ReadPrec RetryPolicy
Int -> ReadS RetryPolicy
ReadS [RetryPolicy]
(Int -> ReadS RetryPolicy)
-> ReadS [RetryPolicy]
-> ReadPrec RetryPolicy
-> ReadPrec [RetryPolicy]
-> Read RetryPolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RetryPolicy]
$creadListPrec :: ReadPrec [RetryPolicy]
readPrec :: ReadPrec RetryPolicy
$creadPrec :: ReadPrec RetryPolicy
readList :: ReadS [RetryPolicy]
$creadList :: ReadS [RetryPolicy]
readsPrec :: Int -> ReadS RetryPolicy
$creadsPrec :: Int -> ReadS RetryPolicy
Prelude.Read, Int -> RetryPolicy -> ShowS
[RetryPolicy] -> ShowS
RetryPolicy -> String
(Int -> RetryPolicy -> ShowS)
-> (RetryPolicy -> String)
-> ([RetryPolicy] -> ShowS)
-> Show RetryPolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RetryPolicy] -> ShowS
$cshowList :: [RetryPolicy] -> ShowS
show :: RetryPolicy -> String
$cshow :: RetryPolicy -> String
showsPrec :: Int -> RetryPolicy -> ShowS
$cshowsPrec :: Int -> RetryPolicy -> ShowS
Prelude.Show, (forall x. RetryPolicy -> Rep RetryPolicy x)
-> (forall x. Rep RetryPolicy x -> RetryPolicy)
-> Generic RetryPolicy
forall x. Rep RetryPolicy x -> RetryPolicy
forall x. RetryPolicy -> Rep RetryPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RetryPolicy x -> RetryPolicy
$cfrom :: forall x. RetryPolicy -> Rep RetryPolicy x
Prelude.Generic)

-- |
-- Create a value of 'RetryPolicy' 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:
--
-- 'maximumEventAgeInSeconds', 'retryPolicy_maximumEventAgeInSeconds' - The maximum amount of time, in seconds, to continue to make retry
-- attempts.
--
-- 'maximumRetryAttempts', 'retryPolicy_maximumRetryAttempts' - The maximum number of retry attempts to make before the request fails.
-- Retry attempts continue until either the maximum number of attempts is
-- made or until the duration of the @MaximumEventAgeInSeconds@ is met.
newRetryPolicy ::
  RetryPolicy
newRetryPolicy :: RetryPolicy
newRetryPolicy =
  RetryPolicy' :: Maybe Natural -> Maybe Natural -> RetryPolicy
RetryPolicy'
    { $sel:maximumEventAgeInSeconds:RetryPolicy' :: Maybe Natural
maximumEventAgeInSeconds =
        Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:maximumRetryAttempts:RetryPolicy' :: Maybe Natural
maximumRetryAttempts = Maybe Natural
forall a. Maybe a
Prelude.Nothing
    }

-- | The maximum amount of time, in seconds, to continue to make retry
-- attempts.
retryPolicy_maximumEventAgeInSeconds :: Lens.Lens' RetryPolicy (Prelude.Maybe Prelude.Natural)
retryPolicy_maximumEventAgeInSeconds :: (Maybe Natural -> f (Maybe Natural))
-> RetryPolicy -> f RetryPolicy
retryPolicy_maximumEventAgeInSeconds = (RetryPolicy -> Maybe Natural)
-> (RetryPolicy -> Maybe Natural -> RetryPolicy)
-> Lens RetryPolicy RetryPolicy (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RetryPolicy' {Maybe Natural
maximumEventAgeInSeconds :: Maybe Natural
$sel:maximumEventAgeInSeconds:RetryPolicy' :: RetryPolicy -> Maybe Natural
maximumEventAgeInSeconds} -> Maybe Natural
maximumEventAgeInSeconds) (\s :: RetryPolicy
s@RetryPolicy' {} Maybe Natural
a -> RetryPolicy
s {$sel:maximumEventAgeInSeconds:RetryPolicy' :: Maybe Natural
maximumEventAgeInSeconds = Maybe Natural
a} :: RetryPolicy)

-- | The maximum number of retry attempts to make before the request fails.
-- Retry attempts continue until either the maximum number of attempts is
-- made or until the duration of the @MaximumEventAgeInSeconds@ is met.
retryPolicy_maximumRetryAttempts :: Lens.Lens' RetryPolicy (Prelude.Maybe Prelude.Natural)
retryPolicy_maximumRetryAttempts :: (Maybe Natural -> f (Maybe Natural))
-> RetryPolicy -> f RetryPolicy
retryPolicy_maximumRetryAttempts = (RetryPolicy -> Maybe Natural)
-> (RetryPolicy -> Maybe Natural -> RetryPolicy)
-> Lens RetryPolicy RetryPolicy (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RetryPolicy' {Maybe Natural
maximumRetryAttempts :: Maybe Natural
$sel:maximumRetryAttempts:RetryPolicy' :: RetryPolicy -> Maybe Natural
maximumRetryAttempts} -> Maybe Natural
maximumRetryAttempts) (\s :: RetryPolicy
s@RetryPolicy' {} Maybe Natural
a -> RetryPolicy
s {$sel:maximumRetryAttempts:RetryPolicy' :: Maybe Natural
maximumRetryAttempts = Maybe Natural
a} :: RetryPolicy)

instance Core.FromJSON RetryPolicy where
  parseJSON :: Value -> Parser RetryPolicy
parseJSON =
    String
-> (Object -> Parser RetryPolicy) -> Value -> Parser RetryPolicy
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"RetryPolicy"
      ( \Object
x ->
          Maybe Natural -> Maybe Natural -> RetryPolicy
RetryPolicy'
            (Maybe Natural -> Maybe Natural -> RetryPolicy)
-> Parser (Maybe Natural) -> Parser (Maybe Natural -> RetryPolicy)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Natural)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"MaximumEventAgeInSeconds")
            Parser (Maybe Natural -> RetryPolicy)
-> Parser (Maybe Natural) -> Parser RetryPolicy
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Natural)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"MaximumRetryAttempts")
      )

instance Prelude.Hashable RetryPolicy

instance Prelude.NFData RetryPolicy

instance Core.ToJSON RetryPolicy where
  toJSON :: RetryPolicy -> Value
toJSON RetryPolicy' {Maybe Natural
maximumRetryAttempts :: Maybe Natural
maximumEventAgeInSeconds :: Maybe Natural
$sel:maximumRetryAttempts:RetryPolicy' :: RetryPolicy -> Maybe Natural
$sel:maximumEventAgeInSeconds:RetryPolicy' :: RetryPolicy -> Maybe Natural
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"MaximumEventAgeInSeconds" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
maximumEventAgeInSeconds,
            (Text
"MaximumRetryAttempts" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
maximumRetryAttempts
          ]
      )