{-# 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.EMRServerless.Types.AutoStopConfig
-- 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.EMRServerless.Types.AutoStopConfig where

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

-- | The configuration for an application to automatically stop after a
-- certain amount of time being idle.
--
-- /See:/ 'newAutoStopConfig' smart constructor.
data AutoStopConfig = AutoStopConfig'
  { -- | Enables the application to automatically stop after a certain amount of
    -- time being idle. Defaults to true.
    AutoStopConfig -> Maybe Bool
enabled :: Prelude.Maybe Prelude.Bool,
    -- | The amount of idle time in minutes after which your application will
    -- automatically stop. Defaults to 15 minutes.
    AutoStopConfig -> Maybe Natural
idleTimeoutMinutes :: Prelude.Maybe Prelude.Natural
  }
  deriving (AutoStopConfig -> AutoStopConfig -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AutoStopConfig -> AutoStopConfig -> Bool
$c/= :: AutoStopConfig -> AutoStopConfig -> Bool
== :: AutoStopConfig -> AutoStopConfig -> Bool
$c== :: AutoStopConfig -> AutoStopConfig -> Bool
Prelude.Eq, ReadPrec [AutoStopConfig]
ReadPrec AutoStopConfig
Int -> ReadS AutoStopConfig
ReadS [AutoStopConfig]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AutoStopConfig]
$creadListPrec :: ReadPrec [AutoStopConfig]
readPrec :: ReadPrec AutoStopConfig
$creadPrec :: ReadPrec AutoStopConfig
readList :: ReadS [AutoStopConfig]
$creadList :: ReadS [AutoStopConfig]
readsPrec :: Int -> ReadS AutoStopConfig
$creadsPrec :: Int -> ReadS AutoStopConfig
Prelude.Read, Int -> AutoStopConfig -> ShowS
[AutoStopConfig] -> ShowS
AutoStopConfig -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AutoStopConfig] -> ShowS
$cshowList :: [AutoStopConfig] -> ShowS
show :: AutoStopConfig -> String
$cshow :: AutoStopConfig -> String
showsPrec :: Int -> AutoStopConfig -> ShowS
$cshowsPrec :: Int -> AutoStopConfig -> ShowS
Prelude.Show, forall x. Rep AutoStopConfig x -> AutoStopConfig
forall x. AutoStopConfig -> Rep AutoStopConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AutoStopConfig x -> AutoStopConfig
$cfrom :: forall x. AutoStopConfig -> Rep AutoStopConfig x
Prelude.Generic)

-- |
-- Create a value of 'AutoStopConfig' 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:
--
-- 'enabled', 'autoStopConfig_enabled' - Enables the application to automatically stop after a certain amount of
-- time being idle. Defaults to true.
--
-- 'idleTimeoutMinutes', 'autoStopConfig_idleTimeoutMinutes' - The amount of idle time in minutes after which your application will
-- automatically stop. Defaults to 15 minutes.
newAutoStopConfig ::
  AutoStopConfig
newAutoStopConfig :: AutoStopConfig
newAutoStopConfig =
  AutoStopConfig'
    { $sel:enabled:AutoStopConfig' :: Maybe Bool
enabled = forall a. Maybe a
Prelude.Nothing,
      $sel:idleTimeoutMinutes:AutoStopConfig' :: Maybe Natural
idleTimeoutMinutes = forall a. Maybe a
Prelude.Nothing
    }

-- | Enables the application to automatically stop after a certain amount of
-- time being idle. Defaults to true.
autoStopConfig_enabled :: Lens.Lens' AutoStopConfig (Prelude.Maybe Prelude.Bool)
autoStopConfig_enabled :: Lens' AutoStopConfig (Maybe Bool)
autoStopConfig_enabled = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AutoStopConfig' {Maybe Bool
enabled :: Maybe Bool
$sel:enabled:AutoStopConfig' :: AutoStopConfig -> Maybe Bool
enabled} -> Maybe Bool
enabled) (\s :: AutoStopConfig
s@AutoStopConfig' {} Maybe Bool
a -> AutoStopConfig
s {$sel:enabled:AutoStopConfig' :: Maybe Bool
enabled = Maybe Bool
a} :: AutoStopConfig)

-- | The amount of idle time in minutes after which your application will
-- automatically stop. Defaults to 15 minutes.
autoStopConfig_idleTimeoutMinutes :: Lens.Lens' AutoStopConfig (Prelude.Maybe Prelude.Natural)
autoStopConfig_idleTimeoutMinutes :: Lens' AutoStopConfig (Maybe Natural)
autoStopConfig_idleTimeoutMinutes = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AutoStopConfig' {Maybe Natural
idleTimeoutMinutes :: Maybe Natural
$sel:idleTimeoutMinutes:AutoStopConfig' :: AutoStopConfig -> Maybe Natural
idleTimeoutMinutes} -> Maybe Natural
idleTimeoutMinutes) (\s :: AutoStopConfig
s@AutoStopConfig' {} Maybe Natural
a -> AutoStopConfig
s {$sel:idleTimeoutMinutes:AutoStopConfig' :: Maybe Natural
idleTimeoutMinutes = Maybe Natural
a} :: AutoStopConfig)

instance Data.FromJSON AutoStopConfig where
  parseJSON :: Value -> Parser AutoStopConfig
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"AutoStopConfig"
      ( \Object
x ->
          Maybe Bool -> Maybe Natural -> AutoStopConfig
AutoStopConfig'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"enabled")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"idleTimeoutMinutes")
      )

instance Prelude.Hashable AutoStopConfig where
  hashWithSalt :: Int -> AutoStopConfig -> Int
hashWithSalt Int
_salt AutoStopConfig' {Maybe Bool
Maybe Natural
idleTimeoutMinutes :: Maybe Natural
enabled :: Maybe Bool
$sel:idleTimeoutMinutes:AutoStopConfig' :: AutoStopConfig -> Maybe Natural
$sel:enabled:AutoStopConfig' :: AutoStopConfig -> Maybe Bool
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
enabled
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
idleTimeoutMinutes

instance Prelude.NFData AutoStopConfig where
  rnf :: AutoStopConfig -> ()
rnf AutoStopConfig' {Maybe Bool
Maybe Natural
idleTimeoutMinutes :: Maybe Natural
enabled :: Maybe Bool
$sel:idleTimeoutMinutes:AutoStopConfig' :: AutoStopConfig -> Maybe Natural
$sel:enabled:AutoStopConfig' :: AutoStopConfig -> Maybe Bool
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
enabled
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
idleTimeoutMinutes

instance Data.ToJSON AutoStopConfig where
  toJSON :: AutoStopConfig -> Value
toJSON AutoStopConfig' {Maybe Bool
Maybe Natural
idleTimeoutMinutes :: Maybe Natural
enabled :: Maybe Bool
$sel:idleTimeoutMinutes:AutoStopConfig' :: AutoStopConfig -> Maybe Natural
$sel:enabled:AutoStopConfig' :: AutoStopConfig -> Maybe Bool
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"enabled" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
enabled,
            (Key
"idleTimeoutMinutes" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
idleTimeoutMinutes
          ]
      )