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

import qualified Amazonka.Core as Core
import Amazonka.IoT.Types.AbortCriteria
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:/ 'newAbortConfig' smart constructor.
data AbortConfig = AbortConfig'
  { -- | The list of criteria that determine when and how to abort the job.
    AbortConfig -> NonEmpty AbortCriteria
criteriaList :: Prelude.NonEmpty AbortCriteria
  }
  deriving (AbortConfig -> AbortConfig -> Bool
(AbortConfig -> AbortConfig -> Bool)
-> (AbortConfig -> AbortConfig -> Bool) -> Eq AbortConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AbortConfig -> AbortConfig -> Bool
$c/= :: AbortConfig -> AbortConfig -> Bool
== :: AbortConfig -> AbortConfig -> Bool
$c== :: AbortConfig -> AbortConfig -> Bool
Prelude.Eq, ReadPrec [AbortConfig]
ReadPrec AbortConfig
Int -> ReadS AbortConfig
ReadS [AbortConfig]
(Int -> ReadS AbortConfig)
-> ReadS [AbortConfig]
-> ReadPrec AbortConfig
-> ReadPrec [AbortConfig]
-> Read AbortConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AbortConfig]
$creadListPrec :: ReadPrec [AbortConfig]
readPrec :: ReadPrec AbortConfig
$creadPrec :: ReadPrec AbortConfig
readList :: ReadS [AbortConfig]
$creadList :: ReadS [AbortConfig]
readsPrec :: Int -> ReadS AbortConfig
$creadsPrec :: Int -> ReadS AbortConfig
Prelude.Read, Int -> AbortConfig -> ShowS
[AbortConfig] -> ShowS
AbortConfig -> String
(Int -> AbortConfig -> ShowS)
-> (AbortConfig -> String)
-> ([AbortConfig] -> ShowS)
-> Show AbortConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AbortConfig] -> ShowS
$cshowList :: [AbortConfig] -> ShowS
show :: AbortConfig -> String
$cshow :: AbortConfig -> String
showsPrec :: Int -> AbortConfig -> ShowS
$cshowsPrec :: Int -> AbortConfig -> ShowS
Prelude.Show, (forall x. AbortConfig -> Rep AbortConfig x)
-> (forall x. Rep AbortConfig x -> AbortConfig)
-> Generic AbortConfig
forall x. Rep AbortConfig x -> AbortConfig
forall x. AbortConfig -> Rep AbortConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AbortConfig x -> AbortConfig
$cfrom :: forall x. AbortConfig -> Rep AbortConfig x
Prelude.Generic)

-- |
-- Create a value of 'AbortConfig' 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:
--
-- 'criteriaList', 'abortConfig_criteriaList' - The list of criteria that determine when and how to abort the job.
newAbortConfig ::
  -- | 'criteriaList'
  Prelude.NonEmpty AbortCriteria ->
  AbortConfig
newAbortConfig :: NonEmpty AbortCriteria -> AbortConfig
newAbortConfig NonEmpty AbortCriteria
pCriteriaList_ =
  AbortConfig' :: NonEmpty AbortCriteria -> AbortConfig
AbortConfig'
    { $sel:criteriaList:AbortConfig' :: NonEmpty AbortCriteria
criteriaList =
        Tagged (NonEmpty AbortCriteria) (Identity (NonEmpty AbortCriteria))
-> Tagged
     (NonEmpty AbortCriteria) (Identity (NonEmpty AbortCriteria))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged
   (NonEmpty AbortCriteria) (Identity (NonEmpty AbortCriteria))
 -> Tagged
      (NonEmpty AbortCriteria) (Identity (NonEmpty AbortCriteria)))
-> NonEmpty AbortCriteria -> NonEmpty AbortCriteria
forall t b. AReview t b -> b -> t
Lens.# NonEmpty AbortCriteria
pCriteriaList_
    }

-- | The list of criteria that determine when and how to abort the job.
abortConfig_criteriaList :: Lens.Lens' AbortConfig (Prelude.NonEmpty AbortCriteria)
abortConfig_criteriaList :: (NonEmpty AbortCriteria -> f (NonEmpty AbortCriteria))
-> AbortConfig -> f AbortConfig
abortConfig_criteriaList = (AbortConfig -> NonEmpty AbortCriteria)
-> (AbortConfig -> NonEmpty AbortCriteria -> AbortConfig)
-> Lens
     AbortConfig
     AbortConfig
     (NonEmpty AbortCriteria)
     (NonEmpty AbortCriteria)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AbortConfig' {NonEmpty AbortCriteria
criteriaList :: NonEmpty AbortCriteria
$sel:criteriaList:AbortConfig' :: AbortConfig -> NonEmpty AbortCriteria
criteriaList} -> NonEmpty AbortCriteria
criteriaList) (\s :: AbortConfig
s@AbortConfig' {} NonEmpty AbortCriteria
a -> AbortConfig
s {$sel:criteriaList:AbortConfig' :: NonEmpty AbortCriteria
criteriaList = NonEmpty AbortCriteria
a} :: AbortConfig) ((NonEmpty AbortCriteria -> f (NonEmpty AbortCriteria))
 -> AbortConfig -> f AbortConfig)
-> ((NonEmpty AbortCriteria -> f (NonEmpty AbortCriteria))
    -> NonEmpty AbortCriteria -> f (NonEmpty AbortCriteria))
-> (NonEmpty AbortCriteria -> f (NonEmpty AbortCriteria))
-> AbortConfig
-> f AbortConfig
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty AbortCriteria -> f (NonEmpty AbortCriteria))
-> NonEmpty AbortCriteria -> f (NonEmpty AbortCriteria)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON AbortConfig where
  parseJSON :: Value -> Parser AbortConfig
parseJSON =
    String
-> (Object -> Parser AbortConfig) -> Value -> Parser AbortConfig
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"AbortConfig"
      ( \Object
x ->
          NonEmpty AbortCriteria -> AbortConfig
AbortConfig' (NonEmpty AbortCriteria -> AbortConfig)
-> Parser (NonEmpty AbortCriteria) -> Parser AbortConfig
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (NonEmpty AbortCriteria)
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"criteriaList")
      )

instance Prelude.Hashable AbortConfig

instance Prelude.NFData AbortConfig

instance Core.ToJSON AbortConfig where
  toJSON :: AbortConfig -> Value
toJSON AbortConfig' {NonEmpty AbortCriteria
criteriaList :: NonEmpty AbortCriteria
$sel:criteriaList:AbortConfig' :: AbortConfig -> NonEmpty AbortCriteria
..} =
    [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
"criteriaList" Text -> NonEmpty AbortCriteria -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NonEmpty AbortCriteria
criteriaList)]
      )