{-# 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.GreengrassV2.Types.IoTJobAbortCriteria
-- 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.GreengrassV2.Types.IoTJobAbortCriteria where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.GreengrassV2.Types.IoTJobAbortAction
import Amazonka.GreengrassV2.Types.IoTJobExecutionFailureType
import qualified Amazonka.Prelude as Prelude

-- | Contains criteria that define when and how to cancel a job.
--
-- The deployment stops if the following conditions are true:
--
-- 1.  The number of things that receive the deployment exceeds the
--     @minNumberOfExecutedThings@.
--
-- 2.  The percentage of failures with type @failureType@ exceeds the
--     @thresholdPercentage@.
--
-- /See:/ 'newIoTJobAbortCriteria' smart constructor.
data IoTJobAbortCriteria = IoTJobAbortCriteria'
  { -- | The type of job deployment failure that can cancel a job.
    IoTJobAbortCriteria -> IoTJobExecutionFailureType
failureType :: IoTJobExecutionFailureType,
    -- | The action to perform when the criteria are met.
    IoTJobAbortCriteria -> IoTJobAbortAction
action :: IoTJobAbortAction,
    -- | The minimum percentage of @failureType@ failures that occur before the
    -- job can cancel.
    --
    -- This parameter supports up to two digits after the decimal (for example,
    -- you can specify @10.9@ or @10.99@, but not @10.999@).
    IoTJobAbortCriteria -> Double
thresholdPercentage :: Prelude.Double,
    -- | The minimum number of things that receive the configuration before the
    -- job can cancel.
    IoTJobAbortCriteria -> Natural
minNumberOfExecutedThings :: Prelude.Natural
  }
  deriving (IoTJobAbortCriteria -> IoTJobAbortCriteria -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IoTJobAbortCriteria -> IoTJobAbortCriteria -> Bool
$c/= :: IoTJobAbortCriteria -> IoTJobAbortCriteria -> Bool
== :: IoTJobAbortCriteria -> IoTJobAbortCriteria -> Bool
$c== :: IoTJobAbortCriteria -> IoTJobAbortCriteria -> Bool
Prelude.Eq, ReadPrec [IoTJobAbortCriteria]
ReadPrec IoTJobAbortCriteria
Int -> ReadS IoTJobAbortCriteria
ReadS [IoTJobAbortCriteria]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [IoTJobAbortCriteria]
$creadListPrec :: ReadPrec [IoTJobAbortCriteria]
readPrec :: ReadPrec IoTJobAbortCriteria
$creadPrec :: ReadPrec IoTJobAbortCriteria
readList :: ReadS [IoTJobAbortCriteria]
$creadList :: ReadS [IoTJobAbortCriteria]
readsPrec :: Int -> ReadS IoTJobAbortCriteria
$creadsPrec :: Int -> ReadS IoTJobAbortCriteria
Prelude.Read, Int -> IoTJobAbortCriteria -> ShowS
[IoTJobAbortCriteria] -> ShowS
IoTJobAbortCriteria -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IoTJobAbortCriteria] -> ShowS
$cshowList :: [IoTJobAbortCriteria] -> ShowS
show :: IoTJobAbortCriteria -> String
$cshow :: IoTJobAbortCriteria -> String
showsPrec :: Int -> IoTJobAbortCriteria -> ShowS
$cshowsPrec :: Int -> IoTJobAbortCriteria -> ShowS
Prelude.Show, forall x. Rep IoTJobAbortCriteria x -> IoTJobAbortCriteria
forall x. IoTJobAbortCriteria -> Rep IoTJobAbortCriteria x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep IoTJobAbortCriteria x -> IoTJobAbortCriteria
$cfrom :: forall x. IoTJobAbortCriteria -> Rep IoTJobAbortCriteria x
Prelude.Generic)

-- |
-- Create a value of 'IoTJobAbortCriteria' 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:
--
-- 'failureType', 'ioTJobAbortCriteria_failureType' - The type of job deployment failure that can cancel a job.
--
-- 'action', 'ioTJobAbortCriteria_action' - The action to perform when the criteria are met.
--
-- 'thresholdPercentage', 'ioTJobAbortCriteria_thresholdPercentage' - The minimum percentage of @failureType@ failures that occur before the
-- job can cancel.
--
-- This parameter supports up to two digits after the decimal (for example,
-- you can specify @10.9@ or @10.99@, but not @10.999@).
--
-- 'minNumberOfExecutedThings', 'ioTJobAbortCriteria_minNumberOfExecutedThings' - The minimum number of things that receive the configuration before the
-- job can cancel.
newIoTJobAbortCriteria ::
  -- | 'failureType'
  IoTJobExecutionFailureType ->
  -- | 'action'
  IoTJobAbortAction ->
  -- | 'thresholdPercentage'
  Prelude.Double ->
  -- | 'minNumberOfExecutedThings'
  Prelude.Natural ->
  IoTJobAbortCriteria
newIoTJobAbortCriteria :: IoTJobExecutionFailureType
-> IoTJobAbortAction -> Double -> Natural -> IoTJobAbortCriteria
newIoTJobAbortCriteria
  IoTJobExecutionFailureType
pFailureType_
  IoTJobAbortAction
pAction_
  Double
pThresholdPercentage_
  Natural
pMinNumberOfExecutedThings_ =
    IoTJobAbortCriteria'
      { $sel:failureType:IoTJobAbortCriteria' :: IoTJobExecutionFailureType
failureType = IoTJobExecutionFailureType
pFailureType_,
        $sel:action:IoTJobAbortCriteria' :: IoTJobAbortAction
action = IoTJobAbortAction
pAction_,
        $sel:thresholdPercentage:IoTJobAbortCriteria' :: Double
thresholdPercentage = Double
pThresholdPercentage_,
        $sel:minNumberOfExecutedThings:IoTJobAbortCriteria' :: Natural
minNumberOfExecutedThings =
          Natural
pMinNumberOfExecutedThings_
      }

-- | The type of job deployment failure that can cancel a job.
ioTJobAbortCriteria_failureType :: Lens.Lens' IoTJobAbortCriteria IoTJobExecutionFailureType
ioTJobAbortCriteria_failureType :: Lens' IoTJobAbortCriteria IoTJobExecutionFailureType
ioTJobAbortCriteria_failureType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IoTJobAbortCriteria' {IoTJobExecutionFailureType
failureType :: IoTJobExecutionFailureType
$sel:failureType:IoTJobAbortCriteria' :: IoTJobAbortCriteria -> IoTJobExecutionFailureType
failureType} -> IoTJobExecutionFailureType
failureType) (\s :: IoTJobAbortCriteria
s@IoTJobAbortCriteria' {} IoTJobExecutionFailureType
a -> IoTJobAbortCriteria
s {$sel:failureType:IoTJobAbortCriteria' :: IoTJobExecutionFailureType
failureType = IoTJobExecutionFailureType
a} :: IoTJobAbortCriteria)

-- | The action to perform when the criteria are met.
ioTJobAbortCriteria_action :: Lens.Lens' IoTJobAbortCriteria IoTJobAbortAction
ioTJobAbortCriteria_action :: Lens' IoTJobAbortCriteria IoTJobAbortAction
ioTJobAbortCriteria_action = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IoTJobAbortCriteria' {IoTJobAbortAction
action :: IoTJobAbortAction
$sel:action:IoTJobAbortCriteria' :: IoTJobAbortCriteria -> IoTJobAbortAction
action} -> IoTJobAbortAction
action) (\s :: IoTJobAbortCriteria
s@IoTJobAbortCriteria' {} IoTJobAbortAction
a -> IoTJobAbortCriteria
s {$sel:action:IoTJobAbortCriteria' :: IoTJobAbortAction
action = IoTJobAbortAction
a} :: IoTJobAbortCriteria)

-- | The minimum percentage of @failureType@ failures that occur before the
-- job can cancel.
--
-- This parameter supports up to two digits after the decimal (for example,
-- you can specify @10.9@ or @10.99@, but not @10.999@).
ioTJobAbortCriteria_thresholdPercentage :: Lens.Lens' IoTJobAbortCriteria Prelude.Double
ioTJobAbortCriteria_thresholdPercentage :: Lens' IoTJobAbortCriteria Double
ioTJobAbortCriteria_thresholdPercentage = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IoTJobAbortCriteria' {Double
thresholdPercentage :: Double
$sel:thresholdPercentage:IoTJobAbortCriteria' :: IoTJobAbortCriteria -> Double
thresholdPercentage} -> Double
thresholdPercentage) (\s :: IoTJobAbortCriteria
s@IoTJobAbortCriteria' {} Double
a -> IoTJobAbortCriteria
s {$sel:thresholdPercentage:IoTJobAbortCriteria' :: Double
thresholdPercentage = Double
a} :: IoTJobAbortCriteria)

-- | The minimum number of things that receive the configuration before the
-- job can cancel.
ioTJobAbortCriteria_minNumberOfExecutedThings :: Lens.Lens' IoTJobAbortCriteria Prelude.Natural
ioTJobAbortCriteria_minNumberOfExecutedThings :: Lens' IoTJobAbortCriteria Natural
ioTJobAbortCriteria_minNumberOfExecutedThings = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IoTJobAbortCriteria' {Natural
minNumberOfExecutedThings :: Natural
$sel:minNumberOfExecutedThings:IoTJobAbortCriteria' :: IoTJobAbortCriteria -> Natural
minNumberOfExecutedThings} -> Natural
minNumberOfExecutedThings) (\s :: IoTJobAbortCriteria
s@IoTJobAbortCriteria' {} Natural
a -> IoTJobAbortCriteria
s {$sel:minNumberOfExecutedThings:IoTJobAbortCriteria' :: Natural
minNumberOfExecutedThings = Natural
a} :: IoTJobAbortCriteria)

instance Data.FromJSON IoTJobAbortCriteria where
  parseJSON :: Value -> Parser IoTJobAbortCriteria
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"IoTJobAbortCriteria"
      ( \Object
x ->
          IoTJobExecutionFailureType
-> IoTJobAbortAction -> Double -> Natural -> IoTJobAbortCriteria
IoTJobAbortCriteria'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"failureType")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"action")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"thresholdPercentage")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"minNumberOfExecutedThings")
      )

instance Prelude.Hashable IoTJobAbortCriteria where
  hashWithSalt :: Int -> IoTJobAbortCriteria -> Int
hashWithSalt Int
_salt IoTJobAbortCriteria' {Double
Natural
IoTJobAbortAction
IoTJobExecutionFailureType
minNumberOfExecutedThings :: Natural
thresholdPercentage :: Double
action :: IoTJobAbortAction
failureType :: IoTJobExecutionFailureType
$sel:minNumberOfExecutedThings:IoTJobAbortCriteria' :: IoTJobAbortCriteria -> Natural
$sel:thresholdPercentage:IoTJobAbortCriteria' :: IoTJobAbortCriteria -> Double
$sel:action:IoTJobAbortCriteria' :: IoTJobAbortCriteria -> IoTJobAbortAction
$sel:failureType:IoTJobAbortCriteria' :: IoTJobAbortCriteria -> IoTJobExecutionFailureType
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` IoTJobExecutionFailureType
failureType
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` IoTJobAbortAction
action
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Double
thresholdPercentage
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Natural
minNumberOfExecutedThings

instance Prelude.NFData IoTJobAbortCriteria where
  rnf :: IoTJobAbortCriteria -> ()
rnf IoTJobAbortCriteria' {Double
Natural
IoTJobAbortAction
IoTJobExecutionFailureType
minNumberOfExecutedThings :: Natural
thresholdPercentage :: Double
action :: IoTJobAbortAction
failureType :: IoTJobExecutionFailureType
$sel:minNumberOfExecutedThings:IoTJobAbortCriteria' :: IoTJobAbortCriteria -> Natural
$sel:thresholdPercentage:IoTJobAbortCriteria' :: IoTJobAbortCriteria -> Double
$sel:action:IoTJobAbortCriteria' :: IoTJobAbortCriteria -> IoTJobAbortAction
$sel:failureType:IoTJobAbortCriteria' :: IoTJobAbortCriteria -> IoTJobExecutionFailureType
..} =
    forall a. NFData a => a -> ()
Prelude.rnf IoTJobExecutionFailureType
failureType
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf IoTJobAbortAction
action
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Double
thresholdPercentage
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Natural
minNumberOfExecutedThings

instance Data.ToJSON IoTJobAbortCriteria where
  toJSON :: IoTJobAbortCriteria -> Value
toJSON IoTJobAbortCriteria' {Double
Natural
IoTJobAbortAction
IoTJobExecutionFailureType
minNumberOfExecutedThings :: Natural
thresholdPercentage :: Double
action :: IoTJobAbortAction
failureType :: IoTJobExecutionFailureType
$sel:minNumberOfExecutedThings:IoTJobAbortCriteria' :: IoTJobAbortCriteria -> Natural
$sel:thresholdPercentage:IoTJobAbortCriteria' :: IoTJobAbortCriteria -> Double
$sel:action:IoTJobAbortCriteria' :: IoTJobAbortCriteria -> IoTJobAbortAction
$sel:failureType:IoTJobAbortCriteria' :: IoTJobAbortCriteria -> IoTJobExecutionFailureType
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"failureType" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= IoTJobExecutionFailureType
failureType),
            forall a. a -> Maybe a
Prelude.Just (Key
"action" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= IoTJobAbortAction
action),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"thresholdPercentage" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Double
thresholdPercentage),
            forall a. a -> Maybe a
Prelude.Just
              ( Key
"minNumberOfExecutedThings"
                  forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Natural
minNumberOfExecutedThings
              )
          ]
      )