{-# 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.IoT.Types.AwsJobAbortCriteria
-- 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.IoT.Types.AwsJobAbortCriteria where

import qualified Amazonka.Core as Core
import Amazonka.IoT.Types.AwsJobAbortCriteriaAbortAction
import Amazonka.IoT.Types.AwsJobAbortCriteriaFailureType
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The criteria that determine when and how a job abort takes place.
--
-- /See:/ 'newAwsJobAbortCriteria' smart constructor.
data AwsJobAbortCriteria = AwsJobAbortCriteria'
  { -- | The type of job execution failures that can initiate a job abort.
    AwsJobAbortCriteria -> AwsJobAbortCriteriaFailureType
failureType :: AwsJobAbortCriteriaFailureType,
    -- | The type of job action to take to initiate the job abort.
    AwsJobAbortCriteria -> AwsJobAbortCriteriaAbortAction
action :: AwsJobAbortCriteriaAbortAction,
    -- | The minimum percentage of job execution failures that must occur to
    -- initiate the job abort.
    --
    -- Amazon Web Services IoT Core supports up to two digits after the decimal
    -- (for example, 10.9 and 10.99, but not 10.999).
    AwsJobAbortCriteria -> Double
thresholdPercentage :: Prelude.Double,
    -- | The minimum number of things which must receive job execution
    -- notifications before the job can be aborted.
    AwsJobAbortCriteria -> Natural
minNumberOfExecutedThings :: Prelude.Natural
  }
  deriving (AwsJobAbortCriteria -> AwsJobAbortCriteria -> Bool
(AwsJobAbortCriteria -> AwsJobAbortCriteria -> Bool)
-> (AwsJobAbortCriteria -> AwsJobAbortCriteria -> Bool)
-> Eq AwsJobAbortCriteria
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AwsJobAbortCriteria -> AwsJobAbortCriteria -> Bool
$c/= :: AwsJobAbortCriteria -> AwsJobAbortCriteria -> Bool
== :: AwsJobAbortCriteria -> AwsJobAbortCriteria -> Bool
$c== :: AwsJobAbortCriteria -> AwsJobAbortCriteria -> Bool
Prelude.Eq, ReadPrec [AwsJobAbortCriteria]
ReadPrec AwsJobAbortCriteria
Int -> ReadS AwsJobAbortCriteria
ReadS [AwsJobAbortCriteria]
(Int -> ReadS AwsJobAbortCriteria)
-> ReadS [AwsJobAbortCriteria]
-> ReadPrec AwsJobAbortCriteria
-> ReadPrec [AwsJobAbortCriteria]
-> Read AwsJobAbortCriteria
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AwsJobAbortCriteria]
$creadListPrec :: ReadPrec [AwsJobAbortCriteria]
readPrec :: ReadPrec AwsJobAbortCriteria
$creadPrec :: ReadPrec AwsJobAbortCriteria
readList :: ReadS [AwsJobAbortCriteria]
$creadList :: ReadS [AwsJobAbortCriteria]
readsPrec :: Int -> ReadS AwsJobAbortCriteria
$creadsPrec :: Int -> ReadS AwsJobAbortCriteria
Prelude.Read, Int -> AwsJobAbortCriteria -> ShowS
[AwsJobAbortCriteria] -> ShowS
AwsJobAbortCriteria -> String
(Int -> AwsJobAbortCriteria -> ShowS)
-> (AwsJobAbortCriteria -> String)
-> ([AwsJobAbortCriteria] -> ShowS)
-> Show AwsJobAbortCriteria
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AwsJobAbortCriteria] -> ShowS
$cshowList :: [AwsJobAbortCriteria] -> ShowS
show :: AwsJobAbortCriteria -> String
$cshow :: AwsJobAbortCriteria -> String
showsPrec :: Int -> AwsJobAbortCriteria -> ShowS
$cshowsPrec :: Int -> AwsJobAbortCriteria -> ShowS
Prelude.Show, (forall x. AwsJobAbortCriteria -> Rep AwsJobAbortCriteria x)
-> (forall x. Rep AwsJobAbortCriteria x -> AwsJobAbortCriteria)
-> Generic AwsJobAbortCriteria
forall x. Rep AwsJobAbortCriteria x -> AwsJobAbortCriteria
forall x. AwsJobAbortCriteria -> Rep AwsJobAbortCriteria x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AwsJobAbortCriteria x -> AwsJobAbortCriteria
$cfrom :: forall x. AwsJobAbortCriteria -> Rep AwsJobAbortCriteria x
Prelude.Generic)

-- |
-- Create a value of 'AwsJobAbortCriteria' 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', 'awsJobAbortCriteria_failureType' - The type of job execution failures that can initiate a job abort.
--
-- 'action', 'awsJobAbortCriteria_action' - The type of job action to take to initiate the job abort.
--
-- 'thresholdPercentage', 'awsJobAbortCriteria_thresholdPercentage' - The minimum percentage of job execution failures that must occur to
-- initiate the job abort.
--
-- Amazon Web Services IoT Core supports up to two digits after the decimal
-- (for example, 10.9 and 10.99, but not 10.999).
--
-- 'minNumberOfExecutedThings', 'awsJobAbortCriteria_minNumberOfExecutedThings' - The minimum number of things which must receive job execution
-- notifications before the job can be aborted.
newAwsJobAbortCriteria ::
  -- | 'failureType'
  AwsJobAbortCriteriaFailureType ->
  -- | 'action'
  AwsJobAbortCriteriaAbortAction ->
  -- | 'thresholdPercentage'
  Prelude.Double ->
  -- | 'minNumberOfExecutedThings'
  Prelude.Natural ->
  AwsJobAbortCriteria
newAwsJobAbortCriteria :: AwsJobAbortCriteriaFailureType
-> AwsJobAbortCriteriaAbortAction
-> Double
-> Natural
-> AwsJobAbortCriteria
newAwsJobAbortCriteria
  AwsJobAbortCriteriaFailureType
pFailureType_
  AwsJobAbortCriteriaAbortAction
pAction_
  Double
pThresholdPercentage_
  Natural
pMinNumberOfExecutedThings_ =
    AwsJobAbortCriteria' :: AwsJobAbortCriteriaFailureType
-> AwsJobAbortCriteriaAbortAction
-> Double
-> Natural
-> AwsJobAbortCriteria
AwsJobAbortCriteria'
      { $sel:failureType:AwsJobAbortCriteria' :: AwsJobAbortCriteriaFailureType
failureType = AwsJobAbortCriteriaFailureType
pFailureType_,
        $sel:action:AwsJobAbortCriteria' :: AwsJobAbortCriteriaAbortAction
action = AwsJobAbortCriteriaAbortAction
pAction_,
        $sel:thresholdPercentage:AwsJobAbortCriteria' :: Double
thresholdPercentage = Double
pThresholdPercentage_,
        $sel:minNumberOfExecutedThings:AwsJobAbortCriteria' :: Natural
minNumberOfExecutedThings =
          Natural
pMinNumberOfExecutedThings_
      }

-- | The type of job execution failures that can initiate a job abort.
awsJobAbortCriteria_failureType :: Lens.Lens' AwsJobAbortCriteria AwsJobAbortCriteriaFailureType
awsJobAbortCriteria_failureType :: (AwsJobAbortCriteriaFailureType
 -> f AwsJobAbortCriteriaFailureType)
-> AwsJobAbortCriteria -> f AwsJobAbortCriteria
awsJobAbortCriteria_failureType = (AwsJobAbortCriteria -> AwsJobAbortCriteriaFailureType)
-> (AwsJobAbortCriteria
    -> AwsJobAbortCriteriaFailureType -> AwsJobAbortCriteria)
-> Lens
     AwsJobAbortCriteria
     AwsJobAbortCriteria
     AwsJobAbortCriteriaFailureType
     AwsJobAbortCriteriaFailureType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AwsJobAbortCriteria' {AwsJobAbortCriteriaFailureType
failureType :: AwsJobAbortCriteriaFailureType
$sel:failureType:AwsJobAbortCriteria' :: AwsJobAbortCriteria -> AwsJobAbortCriteriaFailureType
failureType} -> AwsJobAbortCriteriaFailureType
failureType) (\s :: AwsJobAbortCriteria
s@AwsJobAbortCriteria' {} AwsJobAbortCriteriaFailureType
a -> AwsJobAbortCriteria
s {$sel:failureType:AwsJobAbortCriteria' :: AwsJobAbortCriteriaFailureType
failureType = AwsJobAbortCriteriaFailureType
a} :: AwsJobAbortCriteria)

-- | The type of job action to take to initiate the job abort.
awsJobAbortCriteria_action :: Lens.Lens' AwsJobAbortCriteria AwsJobAbortCriteriaAbortAction
awsJobAbortCriteria_action :: (AwsJobAbortCriteriaAbortAction
 -> f AwsJobAbortCriteriaAbortAction)
-> AwsJobAbortCriteria -> f AwsJobAbortCriteria
awsJobAbortCriteria_action = (AwsJobAbortCriteria -> AwsJobAbortCriteriaAbortAction)
-> (AwsJobAbortCriteria
    -> AwsJobAbortCriteriaAbortAction -> AwsJobAbortCriteria)
-> Lens
     AwsJobAbortCriteria
     AwsJobAbortCriteria
     AwsJobAbortCriteriaAbortAction
     AwsJobAbortCriteriaAbortAction
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AwsJobAbortCriteria' {AwsJobAbortCriteriaAbortAction
action :: AwsJobAbortCriteriaAbortAction
$sel:action:AwsJobAbortCriteria' :: AwsJobAbortCriteria -> AwsJobAbortCriteriaAbortAction
action} -> AwsJobAbortCriteriaAbortAction
action) (\s :: AwsJobAbortCriteria
s@AwsJobAbortCriteria' {} AwsJobAbortCriteriaAbortAction
a -> AwsJobAbortCriteria
s {$sel:action:AwsJobAbortCriteria' :: AwsJobAbortCriteriaAbortAction
action = AwsJobAbortCriteriaAbortAction
a} :: AwsJobAbortCriteria)

-- | The minimum percentage of job execution failures that must occur to
-- initiate the job abort.
--
-- Amazon Web Services IoT Core supports up to two digits after the decimal
-- (for example, 10.9 and 10.99, but not 10.999).
awsJobAbortCriteria_thresholdPercentage :: Lens.Lens' AwsJobAbortCriteria Prelude.Double
awsJobAbortCriteria_thresholdPercentage :: (Double -> f Double)
-> AwsJobAbortCriteria -> f AwsJobAbortCriteria
awsJobAbortCriteria_thresholdPercentage = (AwsJobAbortCriteria -> Double)
-> (AwsJobAbortCriteria -> Double -> AwsJobAbortCriteria)
-> Lens AwsJobAbortCriteria AwsJobAbortCriteria Double Double
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AwsJobAbortCriteria' {Double
thresholdPercentage :: Double
$sel:thresholdPercentage:AwsJobAbortCriteria' :: AwsJobAbortCriteria -> Double
thresholdPercentage} -> Double
thresholdPercentage) (\s :: AwsJobAbortCriteria
s@AwsJobAbortCriteria' {} Double
a -> AwsJobAbortCriteria
s {$sel:thresholdPercentage:AwsJobAbortCriteria' :: Double
thresholdPercentage = Double
a} :: AwsJobAbortCriteria)

-- | The minimum number of things which must receive job execution
-- notifications before the job can be aborted.
awsJobAbortCriteria_minNumberOfExecutedThings :: Lens.Lens' AwsJobAbortCriteria Prelude.Natural
awsJobAbortCriteria_minNumberOfExecutedThings :: (Natural -> f Natural)
-> AwsJobAbortCriteria -> f AwsJobAbortCriteria
awsJobAbortCriteria_minNumberOfExecutedThings = (AwsJobAbortCriteria -> Natural)
-> (AwsJobAbortCriteria -> Natural -> AwsJobAbortCriteria)
-> Lens AwsJobAbortCriteria AwsJobAbortCriteria Natural Natural
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AwsJobAbortCriteria' {Natural
minNumberOfExecutedThings :: Natural
$sel:minNumberOfExecutedThings:AwsJobAbortCriteria' :: AwsJobAbortCriteria -> Natural
minNumberOfExecutedThings} -> Natural
minNumberOfExecutedThings) (\s :: AwsJobAbortCriteria
s@AwsJobAbortCriteria' {} Natural
a -> AwsJobAbortCriteria
s {$sel:minNumberOfExecutedThings:AwsJobAbortCriteria' :: Natural
minNumberOfExecutedThings = Natural
a} :: AwsJobAbortCriteria)

instance Prelude.Hashable AwsJobAbortCriteria

instance Prelude.NFData AwsJobAbortCriteria

instance Core.ToJSON AwsJobAbortCriteria where
  toJSON :: AwsJobAbortCriteria -> Value
toJSON AwsJobAbortCriteria' {Double
Natural
AwsJobAbortCriteriaAbortAction
AwsJobAbortCriteriaFailureType
minNumberOfExecutedThings :: Natural
thresholdPercentage :: Double
action :: AwsJobAbortCriteriaAbortAction
failureType :: AwsJobAbortCriteriaFailureType
$sel:minNumberOfExecutedThings:AwsJobAbortCriteria' :: AwsJobAbortCriteria -> Natural
$sel:thresholdPercentage:AwsJobAbortCriteria' :: AwsJobAbortCriteria -> Double
$sel:action:AwsJobAbortCriteria' :: AwsJobAbortCriteria -> AwsJobAbortCriteriaAbortAction
$sel:failureType:AwsJobAbortCriteria' :: AwsJobAbortCriteria -> AwsJobAbortCriteriaFailureType
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"failureType" Text -> AwsJobAbortCriteriaFailureType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= AwsJobAbortCriteriaFailureType
failureType),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"action" Text -> AwsJobAbortCriteriaAbortAction -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= AwsJobAbortCriteriaAbortAction
action),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"thresholdPercentage" Text -> Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Double
thresholdPercentage),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              ( Text
"minNumberOfExecutedThings"
                  Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Natural
minNumberOfExecutedThings
              )
          ]
      )