{-# 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.ECS.Types.Ulimit
-- 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.ECS.Types.Ulimit where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.ECS.Types.UlimitName
import qualified Amazonka.Prelude as Prelude

-- | The @ulimit@ settings to pass to the container.
--
-- Amazon ECS tasks hosted on Fargate use the default resource limit values
-- set by the operating system with the exception of the @nofile@ resource
-- limit parameter which Fargate overrides. The @nofile@ resource limit
-- sets a restriction on the number of open files that a container can use.
-- The default @nofile@ soft limit is @1024@ and hard limit is @4096@.
--
-- /See:/ 'newUlimit' smart constructor.
data Ulimit = Ulimit'
  { -- | The @type@ of the @ulimit@.
    Ulimit -> UlimitName
name :: UlimitName,
    -- | The soft limit for the @ulimit@ type.
    Ulimit -> Int
softLimit :: Prelude.Int,
    -- | The hard limit for the @ulimit@ type.
    Ulimit -> Int
hardLimit :: Prelude.Int
  }
  deriving (Ulimit -> Ulimit -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Ulimit -> Ulimit -> Bool
$c/= :: Ulimit -> Ulimit -> Bool
== :: Ulimit -> Ulimit -> Bool
$c== :: Ulimit -> Ulimit -> Bool
Prelude.Eq, ReadPrec [Ulimit]
ReadPrec Ulimit
Int -> ReadS Ulimit
ReadS [Ulimit]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Ulimit]
$creadListPrec :: ReadPrec [Ulimit]
readPrec :: ReadPrec Ulimit
$creadPrec :: ReadPrec Ulimit
readList :: ReadS [Ulimit]
$creadList :: ReadS [Ulimit]
readsPrec :: Int -> ReadS Ulimit
$creadsPrec :: Int -> ReadS Ulimit
Prelude.Read, Int -> Ulimit -> ShowS
[Ulimit] -> ShowS
Ulimit -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Ulimit] -> ShowS
$cshowList :: [Ulimit] -> ShowS
show :: Ulimit -> String
$cshow :: Ulimit -> String
showsPrec :: Int -> Ulimit -> ShowS
$cshowsPrec :: Int -> Ulimit -> ShowS
Prelude.Show, forall x. Rep Ulimit x -> Ulimit
forall x. Ulimit -> Rep Ulimit x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Ulimit x -> Ulimit
$cfrom :: forall x. Ulimit -> Rep Ulimit x
Prelude.Generic)

-- |
-- Create a value of 'Ulimit' 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:
--
-- 'name', 'ulimit_name' - The @type@ of the @ulimit@.
--
-- 'softLimit', 'ulimit_softLimit' - The soft limit for the @ulimit@ type.
--
-- 'hardLimit', 'ulimit_hardLimit' - The hard limit for the @ulimit@ type.
newUlimit ::
  -- | 'name'
  UlimitName ->
  -- | 'softLimit'
  Prelude.Int ->
  -- | 'hardLimit'
  Prelude.Int ->
  Ulimit
newUlimit :: UlimitName -> Int -> Int -> Ulimit
newUlimit UlimitName
pName_ Int
pSoftLimit_ Int
pHardLimit_ =
  Ulimit'
    { $sel:name:Ulimit' :: UlimitName
name = UlimitName
pName_,
      $sel:softLimit:Ulimit' :: Int
softLimit = Int
pSoftLimit_,
      $sel:hardLimit:Ulimit' :: Int
hardLimit = Int
pHardLimit_
    }

-- | The @type@ of the @ulimit@.
ulimit_name :: Lens.Lens' Ulimit UlimitName
ulimit_name :: Lens' Ulimit UlimitName
ulimit_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Ulimit' {UlimitName
name :: UlimitName
$sel:name:Ulimit' :: Ulimit -> UlimitName
name} -> UlimitName
name) (\s :: Ulimit
s@Ulimit' {} UlimitName
a -> Ulimit
s {$sel:name:Ulimit' :: UlimitName
name = UlimitName
a} :: Ulimit)

-- | The soft limit for the @ulimit@ type.
ulimit_softLimit :: Lens.Lens' Ulimit Prelude.Int
ulimit_softLimit :: Lens' Ulimit Int
ulimit_softLimit = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Ulimit' {Int
softLimit :: Int
$sel:softLimit:Ulimit' :: Ulimit -> Int
softLimit} -> Int
softLimit) (\s :: Ulimit
s@Ulimit' {} Int
a -> Ulimit
s {$sel:softLimit:Ulimit' :: Int
softLimit = Int
a} :: Ulimit)

-- | The hard limit for the @ulimit@ type.
ulimit_hardLimit :: Lens.Lens' Ulimit Prelude.Int
ulimit_hardLimit :: Lens' Ulimit Int
ulimit_hardLimit = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Ulimit' {Int
hardLimit :: Int
$sel:hardLimit:Ulimit' :: Ulimit -> Int
hardLimit} -> Int
hardLimit) (\s :: Ulimit
s@Ulimit' {} Int
a -> Ulimit
s {$sel:hardLimit:Ulimit' :: Int
hardLimit = Int
a} :: Ulimit)

instance Data.FromJSON Ulimit where
  parseJSON :: Value -> Parser Ulimit
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Ulimit"
      ( \Object
x ->
          UlimitName -> Int -> Int -> Ulimit
Ulimit'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"name")
            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
"softLimit")
            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
"hardLimit")
      )

instance Prelude.Hashable Ulimit where
  hashWithSalt :: Int -> Ulimit -> Int
hashWithSalt Int
_salt Ulimit' {Int
UlimitName
hardLimit :: Int
softLimit :: Int
name :: UlimitName
$sel:hardLimit:Ulimit' :: Ulimit -> Int
$sel:softLimit:Ulimit' :: Ulimit -> Int
$sel:name:Ulimit' :: Ulimit -> UlimitName
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` UlimitName
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Int
softLimit
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Int
hardLimit

instance Prelude.NFData Ulimit where
  rnf :: Ulimit -> ()
rnf Ulimit' {Int
UlimitName
hardLimit :: Int
softLimit :: Int
name :: UlimitName
$sel:hardLimit:Ulimit' :: Ulimit -> Int
$sel:softLimit:Ulimit' :: Ulimit -> Int
$sel:name:Ulimit' :: Ulimit -> UlimitName
..} =
    forall a. NFData a => a -> ()
Prelude.rnf UlimitName
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
softLimit
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
hardLimit

instance Data.ToJSON Ulimit where
  toJSON :: Ulimit -> Value
toJSON Ulimit' {Int
UlimitName
hardLimit :: Int
softLimit :: Int
name :: UlimitName
$sel:hardLimit:Ulimit' :: Ulimit -> Int
$sel:softLimit:Ulimit' :: Ulimit -> Int
$sel:name:Ulimit' :: Ulimit -> UlimitName
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= UlimitName
name),
            forall a. a -> Maybe a
Prelude.Just (Key
"softLimit" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Int
softLimit),
            forall a. a -> Maybe a
Prelude.Just (Key
"hardLimit" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Int
hardLimit)
          ]
      )