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

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

-- | The retry strategy to use for failed jobs, if the target is an Batch
-- job. If you specify a retry strategy here, it overrides the retry
-- strategy defined in the job definition.
--
-- /See:/ 'newBatchRetryStrategy' smart constructor.
data BatchRetryStrategy = BatchRetryStrategy'
  { -- | The number of times to attempt to retry, if the job fails. Valid values
    -- are 1–10.
    BatchRetryStrategy -> Maybe Int
attempts :: Prelude.Maybe Prelude.Int
  }
  deriving (BatchRetryStrategy -> BatchRetryStrategy -> Bool
(BatchRetryStrategy -> BatchRetryStrategy -> Bool)
-> (BatchRetryStrategy -> BatchRetryStrategy -> Bool)
-> Eq BatchRetryStrategy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BatchRetryStrategy -> BatchRetryStrategy -> Bool
$c/= :: BatchRetryStrategy -> BatchRetryStrategy -> Bool
== :: BatchRetryStrategy -> BatchRetryStrategy -> Bool
$c== :: BatchRetryStrategy -> BatchRetryStrategy -> Bool
Prelude.Eq, ReadPrec [BatchRetryStrategy]
ReadPrec BatchRetryStrategy
Int -> ReadS BatchRetryStrategy
ReadS [BatchRetryStrategy]
(Int -> ReadS BatchRetryStrategy)
-> ReadS [BatchRetryStrategy]
-> ReadPrec BatchRetryStrategy
-> ReadPrec [BatchRetryStrategy]
-> Read BatchRetryStrategy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BatchRetryStrategy]
$creadListPrec :: ReadPrec [BatchRetryStrategy]
readPrec :: ReadPrec BatchRetryStrategy
$creadPrec :: ReadPrec BatchRetryStrategy
readList :: ReadS [BatchRetryStrategy]
$creadList :: ReadS [BatchRetryStrategy]
readsPrec :: Int -> ReadS BatchRetryStrategy
$creadsPrec :: Int -> ReadS BatchRetryStrategy
Prelude.Read, Int -> BatchRetryStrategy -> ShowS
[BatchRetryStrategy] -> ShowS
BatchRetryStrategy -> String
(Int -> BatchRetryStrategy -> ShowS)
-> (BatchRetryStrategy -> String)
-> ([BatchRetryStrategy] -> ShowS)
-> Show BatchRetryStrategy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BatchRetryStrategy] -> ShowS
$cshowList :: [BatchRetryStrategy] -> ShowS
show :: BatchRetryStrategy -> String
$cshow :: BatchRetryStrategy -> String
showsPrec :: Int -> BatchRetryStrategy -> ShowS
$cshowsPrec :: Int -> BatchRetryStrategy -> ShowS
Prelude.Show, (forall x. BatchRetryStrategy -> Rep BatchRetryStrategy x)
-> (forall x. Rep BatchRetryStrategy x -> BatchRetryStrategy)
-> Generic BatchRetryStrategy
forall x. Rep BatchRetryStrategy x -> BatchRetryStrategy
forall x. BatchRetryStrategy -> Rep BatchRetryStrategy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BatchRetryStrategy x -> BatchRetryStrategy
$cfrom :: forall x. BatchRetryStrategy -> Rep BatchRetryStrategy x
Prelude.Generic)

-- |
-- Create a value of 'BatchRetryStrategy' 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:
--
-- 'attempts', 'batchRetryStrategy_attempts' - The number of times to attempt to retry, if the job fails. Valid values
-- are 1–10.
newBatchRetryStrategy ::
  BatchRetryStrategy
newBatchRetryStrategy :: BatchRetryStrategy
newBatchRetryStrategy =
  BatchRetryStrategy' :: Maybe Int -> BatchRetryStrategy
BatchRetryStrategy' {$sel:attempts:BatchRetryStrategy' :: Maybe Int
attempts = Maybe Int
forall a. Maybe a
Prelude.Nothing}

-- | The number of times to attempt to retry, if the job fails. Valid values
-- are 1–10.
batchRetryStrategy_attempts :: Lens.Lens' BatchRetryStrategy (Prelude.Maybe Prelude.Int)
batchRetryStrategy_attempts :: (Maybe Int -> f (Maybe Int))
-> BatchRetryStrategy -> f BatchRetryStrategy
batchRetryStrategy_attempts = (BatchRetryStrategy -> Maybe Int)
-> (BatchRetryStrategy -> Maybe Int -> BatchRetryStrategy)
-> Lens
     BatchRetryStrategy BatchRetryStrategy (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchRetryStrategy' {Maybe Int
attempts :: Maybe Int
$sel:attempts:BatchRetryStrategy' :: BatchRetryStrategy -> Maybe Int
attempts} -> Maybe Int
attempts) (\s :: BatchRetryStrategy
s@BatchRetryStrategy' {} Maybe Int
a -> BatchRetryStrategy
s {$sel:attempts:BatchRetryStrategy' :: Maybe Int
attempts = Maybe Int
a} :: BatchRetryStrategy)

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

instance Prelude.Hashable BatchRetryStrategy

instance Prelude.NFData BatchRetryStrategy

instance Core.ToJSON BatchRetryStrategy where
  toJSON :: BatchRetryStrategy -> Value
toJSON BatchRetryStrategy' {Maybe Int
attempts :: Maybe Int
$sel:attempts:BatchRetryStrategy' :: BatchRetryStrategy -> Maybe Int
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [(Text
"Attempts" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Int -> Pair) -> Maybe Int -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Int
attempts]
      )