{-# 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.MaximumAllowedResources
-- 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.MaximumAllowedResources 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 maximum allowed cumulative resources for an application. No new
-- resources will be created once the limit is hit.
--
-- /See:/ 'newMaximumAllowedResources' smart constructor.
data MaximumAllowedResources = MaximumAllowedResources'
  { -- | The maximum allowed disk for an application.
    MaximumAllowedResources -> Maybe Text
disk :: Prelude.Maybe Prelude.Text,
    -- | The maximum allowed CPU for an application.
    MaximumAllowedResources -> Text
cpu :: Prelude.Text,
    -- | The maximum allowed resources for an application.
    MaximumAllowedResources -> Text
memory :: Prelude.Text
  }
  deriving (MaximumAllowedResources -> MaximumAllowedResources -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MaximumAllowedResources -> MaximumAllowedResources -> Bool
$c/= :: MaximumAllowedResources -> MaximumAllowedResources -> Bool
== :: MaximumAllowedResources -> MaximumAllowedResources -> Bool
$c== :: MaximumAllowedResources -> MaximumAllowedResources -> Bool
Prelude.Eq, ReadPrec [MaximumAllowedResources]
ReadPrec MaximumAllowedResources
Int -> ReadS MaximumAllowedResources
ReadS [MaximumAllowedResources]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MaximumAllowedResources]
$creadListPrec :: ReadPrec [MaximumAllowedResources]
readPrec :: ReadPrec MaximumAllowedResources
$creadPrec :: ReadPrec MaximumAllowedResources
readList :: ReadS [MaximumAllowedResources]
$creadList :: ReadS [MaximumAllowedResources]
readsPrec :: Int -> ReadS MaximumAllowedResources
$creadsPrec :: Int -> ReadS MaximumAllowedResources
Prelude.Read, Int -> MaximumAllowedResources -> ShowS
[MaximumAllowedResources] -> ShowS
MaximumAllowedResources -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MaximumAllowedResources] -> ShowS
$cshowList :: [MaximumAllowedResources] -> ShowS
show :: MaximumAllowedResources -> String
$cshow :: MaximumAllowedResources -> String
showsPrec :: Int -> MaximumAllowedResources -> ShowS
$cshowsPrec :: Int -> MaximumAllowedResources -> ShowS
Prelude.Show, forall x. Rep MaximumAllowedResources x -> MaximumAllowedResources
forall x. MaximumAllowedResources -> Rep MaximumAllowedResources x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MaximumAllowedResources x -> MaximumAllowedResources
$cfrom :: forall x. MaximumAllowedResources -> Rep MaximumAllowedResources x
Prelude.Generic)

-- |
-- Create a value of 'MaximumAllowedResources' 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:
--
-- 'disk', 'maximumAllowedResources_disk' - The maximum allowed disk for an application.
--
-- 'cpu', 'maximumAllowedResources_cpu' - The maximum allowed CPU for an application.
--
-- 'memory', 'maximumAllowedResources_memory' - The maximum allowed resources for an application.
newMaximumAllowedResources ::
  -- | 'cpu'
  Prelude.Text ->
  -- | 'memory'
  Prelude.Text ->
  MaximumAllowedResources
newMaximumAllowedResources :: Text -> Text -> MaximumAllowedResources
newMaximumAllowedResources Text
pCpu_ Text
pMemory_ =
  MaximumAllowedResources'
    { $sel:disk:MaximumAllowedResources' :: Maybe Text
disk = forall a. Maybe a
Prelude.Nothing,
      $sel:cpu:MaximumAllowedResources' :: Text
cpu = Text
pCpu_,
      $sel:memory:MaximumAllowedResources' :: Text
memory = Text
pMemory_
    }

-- | The maximum allowed disk for an application.
maximumAllowedResources_disk :: Lens.Lens' MaximumAllowedResources (Prelude.Maybe Prelude.Text)
maximumAllowedResources_disk :: Lens' MaximumAllowedResources (Maybe Text)
maximumAllowedResources_disk = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MaximumAllowedResources' {Maybe Text
disk :: Maybe Text
$sel:disk:MaximumAllowedResources' :: MaximumAllowedResources -> Maybe Text
disk} -> Maybe Text
disk) (\s :: MaximumAllowedResources
s@MaximumAllowedResources' {} Maybe Text
a -> MaximumAllowedResources
s {$sel:disk:MaximumAllowedResources' :: Maybe Text
disk = Maybe Text
a} :: MaximumAllowedResources)

-- | The maximum allowed CPU for an application.
maximumAllowedResources_cpu :: Lens.Lens' MaximumAllowedResources Prelude.Text
maximumAllowedResources_cpu :: Lens' MaximumAllowedResources Text
maximumAllowedResources_cpu = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MaximumAllowedResources' {Text
cpu :: Text
$sel:cpu:MaximumAllowedResources' :: MaximumAllowedResources -> Text
cpu} -> Text
cpu) (\s :: MaximumAllowedResources
s@MaximumAllowedResources' {} Text
a -> MaximumAllowedResources
s {$sel:cpu:MaximumAllowedResources' :: Text
cpu = Text
a} :: MaximumAllowedResources)

-- | The maximum allowed resources for an application.
maximumAllowedResources_memory :: Lens.Lens' MaximumAllowedResources Prelude.Text
maximumAllowedResources_memory :: Lens' MaximumAllowedResources Text
maximumAllowedResources_memory = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MaximumAllowedResources' {Text
memory :: Text
$sel:memory:MaximumAllowedResources' :: MaximumAllowedResources -> Text
memory} -> Text
memory) (\s :: MaximumAllowedResources
s@MaximumAllowedResources' {} Text
a -> MaximumAllowedResources
s {$sel:memory:MaximumAllowedResources' :: Text
memory = Text
a} :: MaximumAllowedResources)

instance Data.FromJSON MaximumAllowedResources where
  parseJSON :: Value -> Parser MaximumAllowedResources
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"MaximumAllowedResources"
      ( \Object
x ->
          Maybe Text -> Text -> Text -> MaximumAllowedResources
MaximumAllowedResources'
            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
"disk")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"cpu")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"memory")
      )

instance Prelude.Hashable MaximumAllowedResources where
  hashWithSalt :: Int -> MaximumAllowedResources -> Int
hashWithSalt Int
_salt MaximumAllowedResources' {Maybe Text
Text
memory :: Text
cpu :: Text
disk :: Maybe Text
$sel:memory:MaximumAllowedResources' :: MaximumAllowedResources -> Text
$sel:cpu:MaximumAllowedResources' :: MaximumAllowedResources -> Text
$sel:disk:MaximumAllowedResources' :: MaximumAllowedResources -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
disk
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
cpu
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
memory

instance Prelude.NFData MaximumAllowedResources where
  rnf :: MaximumAllowedResources -> ()
rnf MaximumAllowedResources' {Maybe Text
Text
memory :: Text
cpu :: Text
disk :: Maybe Text
$sel:memory:MaximumAllowedResources' :: MaximumAllowedResources -> Text
$sel:cpu:MaximumAllowedResources' :: MaximumAllowedResources -> Text
$sel:disk:MaximumAllowedResources' :: MaximumAllowedResources -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
disk
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
cpu
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
memory

instance Data.ToJSON MaximumAllowedResources where
  toJSON :: MaximumAllowedResources -> Value
toJSON MaximumAllowedResources' {Maybe Text
Text
memory :: Text
cpu :: Text
disk :: Maybe Text
$sel:memory:MaximumAllowedResources' :: MaximumAllowedResources -> Text
$sel:cpu:MaximumAllowedResources' :: MaximumAllowedResources -> Text
$sel:disk:MaximumAllowedResources' :: MaximumAllowedResources -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"disk" 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 Text
disk,
            forall a. a -> Maybe a
Prelude.Just (Key
"cpu" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
cpu),
            forall a. a -> Maybe a
Prelude.Just (Key
"memory" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
memory)
          ]
      )