{-# 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.EMR.Types.AutoTerminationPolicy
-- 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.EMR.Types.AutoTerminationPolicy where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | An auto-termination policy for an Amazon EMR cluster. An
-- auto-termination policy defines the amount of idle time in seconds after
-- which a cluster automatically terminates. For alternative cluster
-- termination options, see
-- <https://docs.aws.amazon.com/emr/latest/ManagementGuide/emr-plan-termination.html Control cluster termination>.
--
-- /See:/ 'newAutoTerminationPolicy' smart constructor.
data AutoTerminationPolicy = AutoTerminationPolicy'
  { -- | Specifies the amount of idle time in seconds after which the cluster
    -- automatically terminates. You can specify a minimum of 60 seconds and a
    -- maximum of 604800 seconds (seven days).
    AutoTerminationPolicy -> Maybe Integer
idleTimeout :: Prelude.Maybe Prelude.Integer
  }
  deriving (AutoTerminationPolicy -> AutoTerminationPolicy -> Bool
(AutoTerminationPolicy -> AutoTerminationPolicy -> Bool)
-> (AutoTerminationPolicy -> AutoTerminationPolicy -> Bool)
-> Eq AutoTerminationPolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AutoTerminationPolicy -> AutoTerminationPolicy -> Bool
$c/= :: AutoTerminationPolicy -> AutoTerminationPolicy -> Bool
== :: AutoTerminationPolicy -> AutoTerminationPolicy -> Bool
$c== :: AutoTerminationPolicy -> AutoTerminationPolicy -> Bool
Prelude.Eq, ReadPrec [AutoTerminationPolicy]
ReadPrec AutoTerminationPolicy
Int -> ReadS AutoTerminationPolicy
ReadS [AutoTerminationPolicy]
(Int -> ReadS AutoTerminationPolicy)
-> ReadS [AutoTerminationPolicy]
-> ReadPrec AutoTerminationPolicy
-> ReadPrec [AutoTerminationPolicy]
-> Read AutoTerminationPolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AutoTerminationPolicy]
$creadListPrec :: ReadPrec [AutoTerminationPolicy]
readPrec :: ReadPrec AutoTerminationPolicy
$creadPrec :: ReadPrec AutoTerminationPolicy
readList :: ReadS [AutoTerminationPolicy]
$creadList :: ReadS [AutoTerminationPolicy]
readsPrec :: Int -> ReadS AutoTerminationPolicy
$creadsPrec :: Int -> ReadS AutoTerminationPolicy
Prelude.Read, Int -> AutoTerminationPolicy -> ShowS
[AutoTerminationPolicy] -> ShowS
AutoTerminationPolicy -> String
(Int -> AutoTerminationPolicy -> ShowS)
-> (AutoTerminationPolicy -> String)
-> ([AutoTerminationPolicy] -> ShowS)
-> Show AutoTerminationPolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AutoTerminationPolicy] -> ShowS
$cshowList :: [AutoTerminationPolicy] -> ShowS
show :: AutoTerminationPolicy -> String
$cshow :: AutoTerminationPolicy -> String
showsPrec :: Int -> AutoTerminationPolicy -> ShowS
$cshowsPrec :: Int -> AutoTerminationPolicy -> ShowS
Prelude.Show, (forall x. AutoTerminationPolicy -> Rep AutoTerminationPolicy x)
-> (forall x. Rep AutoTerminationPolicy x -> AutoTerminationPolicy)
-> Generic AutoTerminationPolicy
forall x. Rep AutoTerminationPolicy x -> AutoTerminationPolicy
forall x. AutoTerminationPolicy -> Rep AutoTerminationPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AutoTerminationPolicy x -> AutoTerminationPolicy
$cfrom :: forall x. AutoTerminationPolicy -> Rep AutoTerminationPolicy x
Prelude.Generic)

-- |
-- Create a value of 'AutoTerminationPolicy' 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:
--
-- 'idleTimeout', 'autoTerminationPolicy_idleTimeout' - Specifies the amount of idle time in seconds after which the cluster
-- automatically terminates. You can specify a minimum of 60 seconds and a
-- maximum of 604800 seconds (seven days).
newAutoTerminationPolicy ::
  AutoTerminationPolicy
newAutoTerminationPolicy :: AutoTerminationPolicy
newAutoTerminationPolicy =
  AutoTerminationPolicy' :: Maybe Integer -> AutoTerminationPolicy
AutoTerminationPolicy'
    { $sel:idleTimeout:AutoTerminationPolicy' :: Maybe Integer
idleTimeout =
        Maybe Integer
forall a. Maybe a
Prelude.Nothing
    }

-- | Specifies the amount of idle time in seconds after which the cluster
-- automatically terminates. You can specify a minimum of 60 seconds and a
-- maximum of 604800 seconds (seven days).
autoTerminationPolicy_idleTimeout :: Lens.Lens' AutoTerminationPolicy (Prelude.Maybe Prelude.Integer)
autoTerminationPolicy_idleTimeout :: (Maybe Integer -> f (Maybe Integer))
-> AutoTerminationPolicy -> f AutoTerminationPolicy
autoTerminationPolicy_idleTimeout = (AutoTerminationPolicy -> Maybe Integer)
-> (AutoTerminationPolicy
    -> Maybe Integer -> AutoTerminationPolicy)
-> Lens
     AutoTerminationPolicy
     AutoTerminationPolicy
     (Maybe Integer)
     (Maybe Integer)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AutoTerminationPolicy' {Maybe Integer
idleTimeout :: Maybe Integer
$sel:idleTimeout:AutoTerminationPolicy' :: AutoTerminationPolicy -> Maybe Integer
idleTimeout} -> Maybe Integer
idleTimeout) (\s :: AutoTerminationPolicy
s@AutoTerminationPolicy' {} Maybe Integer
a -> AutoTerminationPolicy
s {$sel:idleTimeout:AutoTerminationPolicy' :: Maybe Integer
idleTimeout = Maybe Integer
a} :: AutoTerminationPolicy)

instance Core.FromJSON AutoTerminationPolicy where
  parseJSON :: Value -> Parser AutoTerminationPolicy
parseJSON =
    String
-> (Object -> Parser AutoTerminationPolicy)
-> Value
-> Parser AutoTerminationPolicy
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"AutoTerminationPolicy"
      ( \Object
x ->
          Maybe Integer -> AutoTerminationPolicy
AutoTerminationPolicy'
            (Maybe Integer -> AutoTerminationPolicy)
-> Parser (Maybe Integer) -> Parser AutoTerminationPolicy
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Integer)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"IdleTimeout")
      )

instance Prelude.Hashable AutoTerminationPolicy

instance Prelude.NFData AutoTerminationPolicy

instance Core.ToJSON AutoTerminationPolicy where
  toJSON :: AutoTerminationPolicy -> Value
toJSON AutoTerminationPolicy' {Maybe Integer
idleTimeout :: Maybe Integer
$sel:idleTimeout:AutoTerminationPolicy' :: AutoTerminationPolicy -> Maybe Integer
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [(Text
"IdleTimeout" Text -> Integer -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Integer -> Pair) -> Maybe Integer -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Integer
idleTimeout]
      )