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

import Amazonka.CloudWatchEvents.Types.BatchArrayProperties
import Amazonka.CloudWatchEvents.Types.BatchRetryStrategy
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The custom parameters to be used when the target is an Batch job.
--
-- /See:/ 'newBatchParameters' smart constructor.
data BatchParameters = BatchParameters'
  { -- | The retry strategy to use for failed jobs, if the target is an Batch
    -- job. The retry strategy is the number of times to retry the failed job
    -- execution. Valid values are 1–10. When you specify a retry strategy
    -- here, it overrides the retry strategy defined in the job definition.
    BatchParameters -> Maybe BatchRetryStrategy
retryStrategy :: Prelude.Maybe BatchRetryStrategy,
    -- | The array properties for the submitted job, such as the size of the
    -- array. The array size can be between 2 and 10,000. If you specify array
    -- properties for a job, it becomes an array job. This parameter is used
    -- only if the target is an Batch job.
    BatchParameters -> Maybe BatchArrayProperties
arrayProperties :: Prelude.Maybe BatchArrayProperties,
    -- | The ARN or name of the job definition to use if the event target is an
    -- Batch job. This job definition must already exist.
    BatchParameters -> Text
jobDefinition :: Prelude.Text,
    -- | The name to use for this execution of the job, if the target is an Batch
    -- job.
    BatchParameters -> Text
jobName :: Prelude.Text
  }
  deriving (BatchParameters -> BatchParameters -> Bool
(BatchParameters -> BatchParameters -> Bool)
-> (BatchParameters -> BatchParameters -> Bool)
-> Eq BatchParameters
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BatchParameters -> BatchParameters -> Bool
$c/= :: BatchParameters -> BatchParameters -> Bool
== :: BatchParameters -> BatchParameters -> Bool
$c== :: BatchParameters -> BatchParameters -> Bool
Prelude.Eq, ReadPrec [BatchParameters]
ReadPrec BatchParameters
Int -> ReadS BatchParameters
ReadS [BatchParameters]
(Int -> ReadS BatchParameters)
-> ReadS [BatchParameters]
-> ReadPrec BatchParameters
-> ReadPrec [BatchParameters]
-> Read BatchParameters
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BatchParameters]
$creadListPrec :: ReadPrec [BatchParameters]
readPrec :: ReadPrec BatchParameters
$creadPrec :: ReadPrec BatchParameters
readList :: ReadS [BatchParameters]
$creadList :: ReadS [BatchParameters]
readsPrec :: Int -> ReadS BatchParameters
$creadsPrec :: Int -> ReadS BatchParameters
Prelude.Read, Int -> BatchParameters -> ShowS
[BatchParameters] -> ShowS
BatchParameters -> String
(Int -> BatchParameters -> ShowS)
-> (BatchParameters -> String)
-> ([BatchParameters] -> ShowS)
-> Show BatchParameters
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BatchParameters] -> ShowS
$cshowList :: [BatchParameters] -> ShowS
show :: BatchParameters -> String
$cshow :: BatchParameters -> String
showsPrec :: Int -> BatchParameters -> ShowS
$cshowsPrec :: Int -> BatchParameters -> ShowS
Prelude.Show, (forall x. BatchParameters -> Rep BatchParameters x)
-> (forall x. Rep BatchParameters x -> BatchParameters)
-> Generic BatchParameters
forall x. Rep BatchParameters x -> BatchParameters
forall x. BatchParameters -> Rep BatchParameters x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BatchParameters x -> BatchParameters
$cfrom :: forall x. BatchParameters -> Rep BatchParameters x
Prelude.Generic)

-- |
-- Create a value of 'BatchParameters' 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:
--
-- 'retryStrategy', 'batchParameters_retryStrategy' - The retry strategy to use for failed jobs, if the target is an Batch
-- job. The retry strategy is the number of times to retry the failed job
-- execution. Valid values are 1–10. When you specify a retry strategy
-- here, it overrides the retry strategy defined in the job definition.
--
-- 'arrayProperties', 'batchParameters_arrayProperties' - The array properties for the submitted job, such as the size of the
-- array. The array size can be between 2 and 10,000. If you specify array
-- properties for a job, it becomes an array job. This parameter is used
-- only if the target is an Batch job.
--
-- 'jobDefinition', 'batchParameters_jobDefinition' - The ARN or name of the job definition to use if the event target is an
-- Batch job. This job definition must already exist.
--
-- 'jobName', 'batchParameters_jobName' - The name to use for this execution of the job, if the target is an Batch
-- job.
newBatchParameters ::
  -- | 'jobDefinition'
  Prelude.Text ->
  -- | 'jobName'
  Prelude.Text ->
  BatchParameters
newBatchParameters :: Text -> Text -> BatchParameters
newBatchParameters Text
pJobDefinition_ Text
pJobName_ =
  BatchParameters' :: Maybe BatchRetryStrategy
-> Maybe BatchArrayProperties -> Text -> Text -> BatchParameters
BatchParameters'
    { $sel:retryStrategy:BatchParameters' :: Maybe BatchRetryStrategy
retryStrategy = Maybe BatchRetryStrategy
forall a. Maybe a
Prelude.Nothing,
      $sel:arrayProperties:BatchParameters' :: Maybe BatchArrayProperties
arrayProperties = Maybe BatchArrayProperties
forall a. Maybe a
Prelude.Nothing,
      $sel:jobDefinition:BatchParameters' :: Text
jobDefinition = Text
pJobDefinition_,
      $sel:jobName:BatchParameters' :: Text
jobName = Text
pJobName_
    }

-- | The retry strategy to use for failed jobs, if the target is an Batch
-- job. The retry strategy is the number of times to retry the failed job
-- execution. Valid values are 1–10. When you specify a retry strategy
-- here, it overrides the retry strategy defined in the job definition.
batchParameters_retryStrategy :: Lens.Lens' BatchParameters (Prelude.Maybe BatchRetryStrategy)
batchParameters_retryStrategy :: (Maybe BatchRetryStrategy -> f (Maybe BatchRetryStrategy))
-> BatchParameters -> f BatchParameters
batchParameters_retryStrategy = (BatchParameters -> Maybe BatchRetryStrategy)
-> (BatchParameters -> Maybe BatchRetryStrategy -> BatchParameters)
-> Lens
     BatchParameters
     BatchParameters
     (Maybe BatchRetryStrategy)
     (Maybe BatchRetryStrategy)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchParameters' {Maybe BatchRetryStrategy
retryStrategy :: Maybe BatchRetryStrategy
$sel:retryStrategy:BatchParameters' :: BatchParameters -> Maybe BatchRetryStrategy
retryStrategy} -> Maybe BatchRetryStrategy
retryStrategy) (\s :: BatchParameters
s@BatchParameters' {} Maybe BatchRetryStrategy
a -> BatchParameters
s {$sel:retryStrategy:BatchParameters' :: Maybe BatchRetryStrategy
retryStrategy = Maybe BatchRetryStrategy
a} :: BatchParameters)

-- | The array properties for the submitted job, such as the size of the
-- array. The array size can be between 2 and 10,000. If you specify array
-- properties for a job, it becomes an array job. This parameter is used
-- only if the target is an Batch job.
batchParameters_arrayProperties :: Lens.Lens' BatchParameters (Prelude.Maybe BatchArrayProperties)
batchParameters_arrayProperties :: (Maybe BatchArrayProperties -> f (Maybe BatchArrayProperties))
-> BatchParameters -> f BatchParameters
batchParameters_arrayProperties = (BatchParameters -> Maybe BatchArrayProperties)
-> (BatchParameters
    -> Maybe BatchArrayProperties -> BatchParameters)
-> Lens
     BatchParameters
     BatchParameters
     (Maybe BatchArrayProperties)
     (Maybe BatchArrayProperties)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchParameters' {Maybe BatchArrayProperties
arrayProperties :: Maybe BatchArrayProperties
$sel:arrayProperties:BatchParameters' :: BatchParameters -> Maybe BatchArrayProperties
arrayProperties} -> Maybe BatchArrayProperties
arrayProperties) (\s :: BatchParameters
s@BatchParameters' {} Maybe BatchArrayProperties
a -> BatchParameters
s {$sel:arrayProperties:BatchParameters' :: Maybe BatchArrayProperties
arrayProperties = Maybe BatchArrayProperties
a} :: BatchParameters)

-- | The ARN or name of the job definition to use if the event target is an
-- Batch job. This job definition must already exist.
batchParameters_jobDefinition :: Lens.Lens' BatchParameters Prelude.Text
batchParameters_jobDefinition :: (Text -> f Text) -> BatchParameters -> f BatchParameters
batchParameters_jobDefinition = (BatchParameters -> Text)
-> (BatchParameters -> Text -> BatchParameters)
-> Lens BatchParameters BatchParameters Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchParameters' {Text
jobDefinition :: Text
$sel:jobDefinition:BatchParameters' :: BatchParameters -> Text
jobDefinition} -> Text
jobDefinition) (\s :: BatchParameters
s@BatchParameters' {} Text
a -> BatchParameters
s {$sel:jobDefinition:BatchParameters' :: Text
jobDefinition = Text
a} :: BatchParameters)

-- | The name to use for this execution of the job, if the target is an Batch
-- job.
batchParameters_jobName :: Lens.Lens' BatchParameters Prelude.Text
batchParameters_jobName :: (Text -> f Text) -> BatchParameters -> f BatchParameters
batchParameters_jobName = (BatchParameters -> Text)
-> (BatchParameters -> Text -> BatchParameters)
-> Lens BatchParameters BatchParameters Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchParameters' {Text
jobName :: Text
$sel:jobName:BatchParameters' :: BatchParameters -> Text
jobName} -> Text
jobName) (\s :: BatchParameters
s@BatchParameters' {} Text
a -> BatchParameters
s {$sel:jobName:BatchParameters' :: Text
jobName = Text
a} :: BatchParameters)

instance Core.FromJSON BatchParameters where
  parseJSON :: Value -> Parser BatchParameters
parseJSON =
    String
-> (Object -> Parser BatchParameters)
-> Value
-> Parser BatchParameters
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"BatchParameters"
      ( \Object
x ->
          Maybe BatchRetryStrategy
-> Maybe BatchArrayProperties -> Text -> Text -> BatchParameters
BatchParameters'
            (Maybe BatchRetryStrategy
 -> Maybe BatchArrayProperties -> Text -> Text -> BatchParameters)
-> Parser (Maybe BatchRetryStrategy)
-> Parser
     (Maybe BatchArrayProperties -> Text -> Text -> BatchParameters)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe BatchRetryStrategy)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"RetryStrategy")
            Parser
  (Maybe BatchArrayProperties -> Text -> Text -> BatchParameters)
-> Parser (Maybe BatchArrayProperties)
-> Parser (Text -> Text -> BatchParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe BatchArrayProperties)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ArrayProperties")
            Parser (Text -> Text -> BatchParameters)
-> Parser Text -> Parser (Text -> BatchParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"JobDefinition")
            Parser (Text -> BatchParameters)
-> Parser Text -> Parser BatchParameters
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"JobName")
      )

instance Prelude.Hashable BatchParameters

instance Prelude.NFData BatchParameters

instance Core.ToJSON BatchParameters where
  toJSON :: BatchParameters -> Value
toJSON BatchParameters' {Maybe BatchArrayProperties
Maybe BatchRetryStrategy
Text
jobName :: Text
jobDefinition :: Text
arrayProperties :: Maybe BatchArrayProperties
retryStrategy :: Maybe BatchRetryStrategy
$sel:jobName:BatchParameters' :: BatchParameters -> Text
$sel:jobDefinition:BatchParameters' :: BatchParameters -> Text
$sel:arrayProperties:BatchParameters' :: BatchParameters -> Maybe BatchArrayProperties
$sel:retryStrategy:BatchParameters' :: BatchParameters -> Maybe BatchRetryStrategy
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"RetryStrategy" Text -> BatchRetryStrategy -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (BatchRetryStrategy -> Pair)
-> Maybe BatchRetryStrategy -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe BatchRetryStrategy
retryStrategy,
            (Text
"ArrayProperties" Text -> BatchArrayProperties -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (BatchArrayProperties -> Pair)
-> Maybe BatchArrayProperties -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe BatchArrayProperties
arrayProperties,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"JobDefinition" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
jobDefinition),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"JobName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
jobName)
          ]
      )