{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.CloudWatchEvents.Types.RetryPolicy where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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]
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
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. 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'
    { $sel:maximumEventAgeInSeconds:RetryPolicy' :: Maybe Natural
maximumEventAgeInSeconds =
        forall a. Maybe a
Prelude.Nothing,
      $sel:maximumRetryAttempts:RetryPolicy' :: Maybe Natural
maximumRetryAttempts = 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 :: Lens' RetryPolicy (Maybe Natural)
retryPolicy_maximumEventAgeInSeconds = 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 :: Lens' RetryPolicy (Maybe Natural)
retryPolicy_maximumRetryAttempts = 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 Data.FromJSON RetryPolicy where
  parseJSON :: Value -> Parser RetryPolicy
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"RetryPolicy"
      ( \Object
x ->
          Maybe Natural -> Maybe Natural -> RetryPolicy
RetryPolicy'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"MaximumEventAgeInSeconds")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"MaximumRetryAttempts")
      )

instance Prelude.Hashable RetryPolicy where
  hashWithSalt :: Int -> RetryPolicy -> Int
hashWithSalt Int
_salt RetryPolicy' {Maybe Natural
maximumRetryAttempts :: Maybe Natural
maximumEventAgeInSeconds :: Maybe Natural
$sel:maximumRetryAttempts:RetryPolicy' :: RetryPolicy -> Maybe Natural
$sel:maximumEventAgeInSeconds:RetryPolicy' :: RetryPolicy -> Maybe Natural
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
maximumEventAgeInSeconds
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
maximumRetryAttempts

instance Prelude.NFData RetryPolicy where
  rnf :: RetryPolicy -> ()
rnf RetryPolicy' {Maybe Natural
maximumRetryAttempts :: Maybe Natural
maximumEventAgeInSeconds :: Maybe Natural
$sel:maximumRetryAttempts:RetryPolicy' :: RetryPolicy -> Maybe Natural
$sel:maximumEventAgeInSeconds:RetryPolicy' :: RetryPolicy -> Maybe Natural
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
maximumEventAgeInSeconds
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
maximumRetryAttempts

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"MaximumEventAgeInSeconds" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
maximumEventAgeInSeconds,
            (Key
"MaximumRetryAttempts" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
maximumRetryAttempts
          ]
      )