{-# 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.Batch.Types.EvaluateOnExit
-- 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.Batch.Types.EvaluateOnExit where

import Amazonka.Batch.Types.RetryAction
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Specifies a set of conditions to be met, and an action to take (@RETRY@
-- or @EXIT@) if all conditions are met.
--
-- /See:/ 'newEvaluateOnExit' smart constructor.
data EvaluateOnExit = EvaluateOnExit'
  { -- | Contains a glob pattern to match against the decimal representation of
    -- the @ExitCode@ returned for a job. The pattern can be up to 512
    -- characters in length. It can contain only numbers, and can optionally
    -- end with an asterisk (*) so that only the start of the string needs to
    -- be an exact match.
    EvaluateOnExit -> Maybe Text
onExitCode :: Prelude.Maybe Prelude.Text,
    -- | Contains a glob pattern to match against the @Reason@ returned for a
    -- job. The pattern can be up to 512 characters in length. It can contain
    -- letters, numbers, periods (.), colons (:), and white space (including
    -- spaces and tabs). It can optionally end with an asterisk (*) so that
    -- only the start of the string needs to be an exact match.
    EvaluateOnExit -> Maybe Text
onReason :: Prelude.Maybe Prelude.Text,
    -- | Contains a glob pattern to match against the @StatusReason@ returned for
    -- a job. The pattern can be up to 512 characters in length. It can contain
    -- letters, numbers, periods (.), colons (:), and white space (including
    -- spaces or tabs). It can optionally end with an asterisk (*) so that only
    -- the start of the string needs to be an exact match.
    EvaluateOnExit -> Maybe Text
onStatusReason :: Prelude.Maybe Prelude.Text,
    -- | Specifies the action to take if all of the specified conditions
    -- (@onStatusReason@, @onReason@, and @onExitCode@) are met. The values
    -- aren\'t case sensitive.
    EvaluateOnExit -> RetryAction
action :: RetryAction
  }
  deriving (EvaluateOnExit -> EvaluateOnExit -> Bool
(EvaluateOnExit -> EvaluateOnExit -> Bool)
-> (EvaluateOnExit -> EvaluateOnExit -> Bool) -> Eq EvaluateOnExit
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EvaluateOnExit -> EvaluateOnExit -> Bool
$c/= :: EvaluateOnExit -> EvaluateOnExit -> Bool
== :: EvaluateOnExit -> EvaluateOnExit -> Bool
$c== :: EvaluateOnExit -> EvaluateOnExit -> Bool
Prelude.Eq, ReadPrec [EvaluateOnExit]
ReadPrec EvaluateOnExit
Int -> ReadS EvaluateOnExit
ReadS [EvaluateOnExit]
(Int -> ReadS EvaluateOnExit)
-> ReadS [EvaluateOnExit]
-> ReadPrec EvaluateOnExit
-> ReadPrec [EvaluateOnExit]
-> Read EvaluateOnExit
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EvaluateOnExit]
$creadListPrec :: ReadPrec [EvaluateOnExit]
readPrec :: ReadPrec EvaluateOnExit
$creadPrec :: ReadPrec EvaluateOnExit
readList :: ReadS [EvaluateOnExit]
$creadList :: ReadS [EvaluateOnExit]
readsPrec :: Int -> ReadS EvaluateOnExit
$creadsPrec :: Int -> ReadS EvaluateOnExit
Prelude.Read, Int -> EvaluateOnExit -> ShowS
[EvaluateOnExit] -> ShowS
EvaluateOnExit -> String
(Int -> EvaluateOnExit -> ShowS)
-> (EvaluateOnExit -> String)
-> ([EvaluateOnExit] -> ShowS)
-> Show EvaluateOnExit
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EvaluateOnExit] -> ShowS
$cshowList :: [EvaluateOnExit] -> ShowS
show :: EvaluateOnExit -> String
$cshow :: EvaluateOnExit -> String
showsPrec :: Int -> EvaluateOnExit -> ShowS
$cshowsPrec :: Int -> EvaluateOnExit -> ShowS
Prelude.Show, (forall x. EvaluateOnExit -> Rep EvaluateOnExit x)
-> (forall x. Rep EvaluateOnExit x -> EvaluateOnExit)
-> Generic EvaluateOnExit
forall x. Rep EvaluateOnExit x -> EvaluateOnExit
forall x. EvaluateOnExit -> Rep EvaluateOnExit x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep EvaluateOnExit x -> EvaluateOnExit
$cfrom :: forall x. EvaluateOnExit -> Rep EvaluateOnExit x
Prelude.Generic)

-- |
-- Create a value of 'EvaluateOnExit' 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:
--
-- 'onExitCode', 'evaluateOnExit_onExitCode' - Contains a glob pattern to match against the decimal representation of
-- the @ExitCode@ returned for a job. The pattern can be up to 512
-- characters in length. It can contain only numbers, and can optionally
-- end with an asterisk (*) so that only the start of the string needs to
-- be an exact match.
--
-- 'onReason', 'evaluateOnExit_onReason' - Contains a glob pattern to match against the @Reason@ returned for a
-- job. The pattern can be up to 512 characters in length. It can contain
-- letters, numbers, periods (.), colons (:), and white space (including
-- spaces and tabs). It can optionally end with an asterisk (*) so that
-- only the start of the string needs to be an exact match.
--
-- 'onStatusReason', 'evaluateOnExit_onStatusReason' - Contains a glob pattern to match against the @StatusReason@ returned for
-- a job. The pattern can be up to 512 characters in length. It can contain
-- letters, numbers, periods (.), colons (:), and white space (including
-- spaces or tabs). It can optionally end with an asterisk (*) so that only
-- the start of the string needs to be an exact match.
--
-- 'action', 'evaluateOnExit_action' - Specifies the action to take if all of the specified conditions
-- (@onStatusReason@, @onReason@, and @onExitCode@) are met. The values
-- aren\'t case sensitive.
newEvaluateOnExit ::
  -- | 'action'
  RetryAction ->
  EvaluateOnExit
newEvaluateOnExit :: RetryAction -> EvaluateOnExit
newEvaluateOnExit RetryAction
pAction_ =
  EvaluateOnExit' :: Maybe Text
-> Maybe Text -> Maybe Text -> RetryAction -> EvaluateOnExit
EvaluateOnExit'
    { $sel:onExitCode:EvaluateOnExit' :: Maybe Text
onExitCode = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:onReason:EvaluateOnExit' :: Maybe Text
onReason = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:onStatusReason:EvaluateOnExit' :: Maybe Text
onStatusReason = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:action:EvaluateOnExit' :: RetryAction
action = RetryAction
pAction_
    }

-- | Contains a glob pattern to match against the decimal representation of
-- the @ExitCode@ returned for a job. The pattern can be up to 512
-- characters in length. It can contain only numbers, and can optionally
-- end with an asterisk (*) so that only the start of the string needs to
-- be an exact match.
evaluateOnExit_onExitCode :: Lens.Lens' EvaluateOnExit (Prelude.Maybe Prelude.Text)
evaluateOnExit_onExitCode :: (Maybe Text -> f (Maybe Text))
-> EvaluateOnExit -> f EvaluateOnExit
evaluateOnExit_onExitCode = (EvaluateOnExit -> Maybe Text)
-> (EvaluateOnExit -> Maybe Text -> EvaluateOnExit)
-> Lens EvaluateOnExit EvaluateOnExit (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EvaluateOnExit' {Maybe Text
onExitCode :: Maybe Text
$sel:onExitCode:EvaluateOnExit' :: EvaluateOnExit -> Maybe Text
onExitCode} -> Maybe Text
onExitCode) (\s :: EvaluateOnExit
s@EvaluateOnExit' {} Maybe Text
a -> EvaluateOnExit
s {$sel:onExitCode:EvaluateOnExit' :: Maybe Text
onExitCode = Maybe Text
a} :: EvaluateOnExit)

-- | Contains a glob pattern to match against the @Reason@ returned for a
-- job. The pattern can be up to 512 characters in length. It can contain
-- letters, numbers, periods (.), colons (:), and white space (including
-- spaces and tabs). It can optionally end with an asterisk (*) so that
-- only the start of the string needs to be an exact match.
evaluateOnExit_onReason :: Lens.Lens' EvaluateOnExit (Prelude.Maybe Prelude.Text)
evaluateOnExit_onReason :: (Maybe Text -> f (Maybe Text))
-> EvaluateOnExit -> f EvaluateOnExit
evaluateOnExit_onReason = (EvaluateOnExit -> Maybe Text)
-> (EvaluateOnExit -> Maybe Text -> EvaluateOnExit)
-> Lens EvaluateOnExit EvaluateOnExit (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EvaluateOnExit' {Maybe Text
onReason :: Maybe Text
$sel:onReason:EvaluateOnExit' :: EvaluateOnExit -> Maybe Text
onReason} -> Maybe Text
onReason) (\s :: EvaluateOnExit
s@EvaluateOnExit' {} Maybe Text
a -> EvaluateOnExit
s {$sel:onReason:EvaluateOnExit' :: Maybe Text
onReason = Maybe Text
a} :: EvaluateOnExit)

-- | Contains a glob pattern to match against the @StatusReason@ returned for
-- a job. The pattern can be up to 512 characters in length. It can contain
-- letters, numbers, periods (.), colons (:), and white space (including
-- spaces or tabs). It can optionally end with an asterisk (*) so that only
-- the start of the string needs to be an exact match.
evaluateOnExit_onStatusReason :: Lens.Lens' EvaluateOnExit (Prelude.Maybe Prelude.Text)
evaluateOnExit_onStatusReason :: (Maybe Text -> f (Maybe Text))
-> EvaluateOnExit -> f EvaluateOnExit
evaluateOnExit_onStatusReason = (EvaluateOnExit -> Maybe Text)
-> (EvaluateOnExit -> Maybe Text -> EvaluateOnExit)
-> Lens EvaluateOnExit EvaluateOnExit (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EvaluateOnExit' {Maybe Text
onStatusReason :: Maybe Text
$sel:onStatusReason:EvaluateOnExit' :: EvaluateOnExit -> Maybe Text
onStatusReason} -> Maybe Text
onStatusReason) (\s :: EvaluateOnExit
s@EvaluateOnExit' {} Maybe Text
a -> EvaluateOnExit
s {$sel:onStatusReason:EvaluateOnExit' :: Maybe Text
onStatusReason = Maybe Text
a} :: EvaluateOnExit)

-- | Specifies the action to take if all of the specified conditions
-- (@onStatusReason@, @onReason@, and @onExitCode@) are met. The values
-- aren\'t case sensitive.
evaluateOnExit_action :: Lens.Lens' EvaluateOnExit RetryAction
evaluateOnExit_action :: (RetryAction -> f RetryAction)
-> EvaluateOnExit -> f EvaluateOnExit
evaluateOnExit_action = (EvaluateOnExit -> RetryAction)
-> (EvaluateOnExit -> RetryAction -> EvaluateOnExit)
-> Lens EvaluateOnExit EvaluateOnExit RetryAction RetryAction
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EvaluateOnExit' {RetryAction
action :: RetryAction
$sel:action:EvaluateOnExit' :: EvaluateOnExit -> RetryAction
action} -> RetryAction
action) (\s :: EvaluateOnExit
s@EvaluateOnExit' {} RetryAction
a -> EvaluateOnExit
s {$sel:action:EvaluateOnExit' :: RetryAction
action = RetryAction
a} :: EvaluateOnExit)

instance Core.FromJSON EvaluateOnExit where
  parseJSON :: Value -> Parser EvaluateOnExit
parseJSON =
    String
-> (Object -> Parser EvaluateOnExit)
-> Value
-> Parser EvaluateOnExit
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"EvaluateOnExit"
      ( \Object
x ->
          Maybe Text
-> Maybe Text -> Maybe Text -> RetryAction -> EvaluateOnExit
EvaluateOnExit'
            (Maybe Text
 -> Maybe Text -> Maybe Text -> RetryAction -> EvaluateOnExit)
-> Parser (Maybe Text)
-> Parser
     (Maybe Text -> Maybe Text -> RetryAction -> EvaluateOnExit)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"onExitCode")
            Parser (Maybe Text -> Maybe Text -> RetryAction -> EvaluateOnExit)
-> Parser (Maybe Text)
-> Parser (Maybe Text -> RetryAction -> EvaluateOnExit)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"onReason")
            Parser (Maybe Text -> RetryAction -> EvaluateOnExit)
-> Parser (Maybe Text) -> Parser (RetryAction -> EvaluateOnExit)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"onStatusReason")
            Parser (RetryAction -> EvaluateOnExit)
-> Parser RetryAction -> Parser EvaluateOnExit
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser RetryAction
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"action")
      )

instance Prelude.Hashable EvaluateOnExit

instance Prelude.NFData EvaluateOnExit

instance Core.ToJSON EvaluateOnExit where
  toJSON :: EvaluateOnExit -> Value
toJSON EvaluateOnExit' {Maybe Text
RetryAction
action :: RetryAction
onStatusReason :: Maybe Text
onReason :: Maybe Text
onExitCode :: Maybe Text
$sel:action:EvaluateOnExit' :: EvaluateOnExit -> RetryAction
$sel:onStatusReason:EvaluateOnExit' :: EvaluateOnExit -> Maybe Text
$sel:onReason:EvaluateOnExit' :: EvaluateOnExit -> Maybe Text
$sel:onExitCode:EvaluateOnExit' :: EvaluateOnExit -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"onExitCode" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
onExitCode,
            (Text
"onReason" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
onReason,
            (Text
"onStatusReason" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
onStatusReason,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"action" Text -> RetryAction -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= RetryAction
action)
          ]
      )