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

-- | The retry strategy that\'s associated with a job. For more information,
-- see
-- <https://docs.aws.amazon.com/batch/latest/userguide/job_retries.html Automated job retries>
-- in the /Batch User Guide/.
--
-- /See:/ 'newBatchRetryStrategy' smart constructor.
data BatchRetryStrategy = BatchRetryStrategy'
  { -- | The number of times to move a job to the @RUNNABLE@ status. If the value
    -- of @attempts@ is greater than one, the job is retried on failure the
    -- same number of attempts as the value.
    BatchRetryStrategy -> Maybe Natural
attempts :: Prelude.Maybe Prelude.Natural
  }
  deriving (BatchRetryStrategy -> BatchRetryStrategy -> Bool
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]
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
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. 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 move a job to the @RUNNABLE@ status. If the value
-- of @attempts@ is greater than one, the job is retried on failure the
-- same number of attempts as the value.
newBatchRetryStrategy ::
  BatchRetryStrategy
newBatchRetryStrategy :: BatchRetryStrategy
newBatchRetryStrategy =
  BatchRetryStrategy' {$sel:attempts:BatchRetryStrategy' :: Maybe Natural
attempts = forall a. Maybe a
Prelude.Nothing}

-- | The number of times to move a job to the @RUNNABLE@ status. If the value
-- of @attempts@ is greater than one, the job is retried on failure the
-- same number of attempts as the value.
batchRetryStrategy_attempts :: Lens.Lens' BatchRetryStrategy (Prelude.Maybe Prelude.Natural)
batchRetryStrategy_attempts :: Lens' BatchRetryStrategy (Maybe Natural)
batchRetryStrategy_attempts = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchRetryStrategy' {Maybe Natural
attempts :: Maybe Natural
$sel:attempts:BatchRetryStrategy' :: BatchRetryStrategy -> Maybe Natural
attempts} -> Maybe Natural
attempts) (\s :: BatchRetryStrategy
s@BatchRetryStrategy' {} Maybe Natural
a -> BatchRetryStrategy
s {$sel:attempts:BatchRetryStrategy' :: Maybe Natural
attempts = Maybe Natural
a} :: BatchRetryStrategy)

instance Data.FromJSON BatchRetryStrategy where
  parseJSON :: Value -> Parser BatchRetryStrategy
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"BatchRetryStrategy"
      ( \Object
x ->
          Maybe Natural -> BatchRetryStrategy
BatchRetryStrategy'
            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
"Attempts")
      )

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

instance Prelude.NFData BatchRetryStrategy where
  rnf :: BatchRetryStrategy -> ()
rnf BatchRetryStrategy' {Maybe Natural
attempts :: Maybe Natural
$sel:attempts:BatchRetryStrategy' :: BatchRetryStrategy -> Maybe Natural
..} = forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
attempts

instance Data.ToJSON BatchRetryStrategy where
  toJSON :: BatchRetryStrategy -> Value
toJSON BatchRetryStrategy' {Maybe Natural
attempts :: Maybe Natural
$sel:attempts:BatchRetryStrategy' :: BatchRetryStrategy -> Maybe Natural
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [(Key
"Attempts" 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
attempts]
      )