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

import qualified Amazonka.Core as Core
import Amazonka.IoT.Types.AbortAction
import Amazonka.IoT.Types.JobExecutionFailureType
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:/ 'newAbortCriteria' smart constructor.
data AbortCriteria = AbortCriteria'
  { -- | The type of job execution failures that can initiate a job abort.
    AbortCriteria -> JobExecutionFailureType
failureType :: JobExecutionFailureType,
    -- | The type of job action to take to initiate the job abort.
    AbortCriteria -> AbortAction
action :: AbortAction,
    -- | 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).
    AbortCriteria -> Double
thresholdPercentage :: Prelude.Double,
    -- | The minimum number of things which must receive job execution
    -- notifications before the job can be aborted.
    AbortCriteria -> Natural
minNumberOfExecutedThings :: Prelude.Natural
  }
  deriving (AbortCriteria -> AbortCriteria -> Bool
(AbortCriteria -> AbortCriteria -> Bool)
-> (AbortCriteria -> AbortCriteria -> Bool) -> Eq AbortCriteria
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AbortCriteria -> AbortCriteria -> Bool
$c/= :: AbortCriteria -> AbortCriteria -> Bool
== :: AbortCriteria -> AbortCriteria -> Bool
$c== :: AbortCriteria -> AbortCriteria -> Bool
Prelude.Eq, ReadPrec [AbortCriteria]
ReadPrec AbortCriteria
Int -> ReadS AbortCriteria
ReadS [AbortCriteria]
(Int -> ReadS AbortCriteria)
-> ReadS [AbortCriteria]
-> ReadPrec AbortCriteria
-> ReadPrec [AbortCriteria]
-> Read AbortCriteria
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AbortCriteria]
$creadListPrec :: ReadPrec [AbortCriteria]
readPrec :: ReadPrec AbortCriteria
$creadPrec :: ReadPrec AbortCriteria
readList :: ReadS [AbortCriteria]
$creadList :: ReadS [AbortCriteria]
readsPrec :: Int -> ReadS AbortCriteria
$creadsPrec :: Int -> ReadS AbortCriteria
Prelude.Read, Int -> AbortCriteria -> ShowS
[AbortCriteria] -> ShowS
AbortCriteria -> String
(Int -> AbortCriteria -> ShowS)
-> (AbortCriteria -> String)
-> ([AbortCriteria] -> ShowS)
-> Show AbortCriteria
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AbortCriteria] -> ShowS
$cshowList :: [AbortCriteria] -> ShowS
show :: AbortCriteria -> String
$cshow :: AbortCriteria -> String
showsPrec :: Int -> AbortCriteria -> ShowS
$cshowsPrec :: Int -> AbortCriteria -> ShowS
Prelude.Show, (forall x. AbortCriteria -> Rep AbortCriteria x)
-> (forall x. Rep AbortCriteria x -> AbortCriteria)
-> Generic AbortCriteria
forall x. Rep AbortCriteria x -> AbortCriteria
forall x. AbortCriteria -> Rep AbortCriteria x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AbortCriteria x -> AbortCriteria
$cfrom :: forall x. AbortCriteria -> Rep AbortCriteria x
Prelude.Generic)

-- |
-- Create a value of 'AbortCriteria' 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', 'abortCriteria_failureType' - The type of job execution failures that can initiate a job abort.
--
-- 'action', 'abortCriteria_action' - The type of job action to take to initiate the job abort.
--
-- 'thresholdPercentage', 'abortCriteria_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', 'abortCriteria_minNumberOfExecutedThings' - The minimum number of things which must receive job execution
-- notifications before the job can be aborted.
newAbortCriteria ::
  -- | 'failureType'
  JobExecutionFailureType ->
  -- | 'action'
  AbortAction ->
  -- | 'thresholdPercentage'
  Prelude.Double ->
  -- | 'minNumberOfExecutedThings'
  Prelude.Natural ->
  AbortCriteria
newAbortCriteria :: JobExecutionFailureType
-> AbortAction -> Double -> Natural -> AbortCriteria
newAbortCriteria
  JobExecutionFailureType
pFailureType_
  AbortAction
pAction_
  Double
pThresholdPercentage_
  Natural
pMinNumberOfExecutedThings_ =
    AbortCriteria' :: JobExecutionFailureType
-> AbortAction -> Double -> Natural -> AbortCriteria
AbortCriteria'
      { $sel:failureType:AbortCriteria' :: JobExecutionFailureType
failureType = JobExecutionFailureType
pFailureType_,
        $sel:action:AbortCriteria' :: AbortAction
action = AbortAction
pAction_,
        $sel:thresholdPercentage:AbortCriteria' :: Double
thresholdPercentage = Double
pThresholdPercentage_,
        $sel:minNumberOfExecutedThings:AbortCriteria' :: Natural
minNumberOfExecutedThings =
          Natural
pMinNumberOfExecutedThings_
      }

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

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

-- | 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).
abortCriteria_thresholdPercentage :: Lens.Lens' AbortCriteria Prelude.Double
abortCriteria_thresholdPercentage :: (Double -> f Double) -> AbortCriteria -> f AbortCriteria
abortCriteria_thresholdPercentage = (AbortCriteria -> Double)
-> (AbortCriteria -> Double -> AbortCriteria)
-> Lens AbortCriteria AbortCriteria Double Double
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AbortCriteria' {Double
thresholdPercentage :: Double
$sel:thresholdPercentage:AbortCriteria' :: AbortCriteria -> Double
thresholdPercentage} -> Double
thresholdPercentage) (\s :: AbortCriteria
s@AbortCriteria' {} Double
a -> AbortCriteria
s {$sel:thresholdPercentage:AbortCriteria' :: Double
thresholdPercentage = Double
a} :: AbortCriteria)

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

instance Core.FromJSON AbortCriteria where
  parseJSON :: Value -> Parser AbortCriteria
parseJSON =
    String
-> (Object -> Parser AbortCriteria)
-> Value
-> Parser AbortCriteria
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"AbortCriteria"
      ( \Object
x ->
          JobExecutionFailureType
-> AbortAction -> Double -> Natural -> AbortCriteria
AbortCriteria'
            (JobExecutionFailureType
 -> AbortAction -> Double -> Natural -> AbortCriteria)
-> Parser JobExecutionFailureType
-> Parser (AbortAction -> Double -> Natural -> AbortCriteria)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser JobExecutionFailureType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"failureType")
            Parser (AbortAction -> Double -> Natural -> AbortCriteria)
-> Parser AbortAction
-> Parser (Double -> Natural -> AbortCriteria)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser AbortAction
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"action")
            Parser (Double -> Natural -> AbortCriteria)
-> Parser Double -> Parser (Natural -> AbortCriteria)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Double
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"thresholdPercentage")
            Parser (Natural -> AbortCriteria)
-> Parser Natural -> Parser AbortCriteria
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Natural
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"minNumberOfExecutedThings")
      )

instance Prelude.Hashable AbortCriteria

instance Prelude.NFData AbortCriteria

instance Core.ToJSON AbortCriteria where
  toJSON :: AbortCriteria -> Value
toJSON AbortCriteria' {Double
Natural
AbortAction
JobExecutionFailureType
minNumberOfExecutedThings :: Natural
thresholdPercentage :: Double
action :: AbortAction
failureType :: JobExecutionFailureType
$sel:minNumberOfExecutedThings:AbortCriteria' :: AbortCriteria -> Natural
$sel:thresholdPercentage:AbortCriteria' :: AbortCriteria -> Double
$sel:action:AbortCriteria' :: AbortCriteria -> AbortAction
$sel:failureType:AbortCriteria' :: AbortCriteria -> JobExecutionFailureType
..} =
    [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 -> JobExecutionFailureType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= JobExecutionFailureType
failureType),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"action" Text -> AbortAction -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= AbortAction
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
              )
          ]
      )