{-# 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.ElasticBeanstalk.Types.MaxCountRule
-- 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.ElasticBeanstalk.Types.MaxCountRule 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

-- | A lifecycle rule that deletes the oldest application version when the
-- maximum count is exceeded.
--
-- /See:/ 'newMaxCountRule' smart constructor.
data MaxCountRule = MaxCountRule'
  { -- | Set to @true@ to delete a version\'s source bundle from Amazon S3 when
    -- Elastic Beanstalk deletes the application version.
    MaxCountRule -> Maybe Bool
deleteSourceFromS3 :: Prelude.Maybe Prelude.Bool,
    -- | Specify the maximum number of application versions to retain.
    MaxCountRule -> Maybe Int
maxCount :: Prelude.Maybe Prelude.Int,
    -- | Specify @true@ to apply the rule, or @false@ to disable it.
    MaxCountRule -> Bool
enabled :: Prelude.Bool
  }
  deriving (MaxCountRule -> MaxCountRule -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MaxCountRule -> MaxCountRule -> Bool
$c/= :: MaxCountRule -> MaxCountRule -> Bool
== :: MaxCountRule -> MaxCountRule -> Bool
$c== :: MaxCountRule -> MaxCountRule -> Bool
Prelude.Eq, ReadPrec [MaxCountRule]
ReadPrec MaxCountRule
Int -> ReadS MaxCountRule
ReadS [MaxCountRule]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MaxCountRule]
$creadListPrec :: ReadPrec [MaxCountRule]
readPrec :: ReadPrec MaxCountRule
$creadPrec :: ReadPrec MaxCountRule
readList :: ReadS [MaxCountRule]
$creadList :: ReadS [MaxCountRule]
readsPrec :: Int -> ReadS MaxCountRule
$creadsPrec :: Int -> ReadS MaxCountRule
Prelude.Read, Int -> MaxCountRule -> ShowS
[MaxCountRule] -> ShowS
MaxCountRule -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MaxCountRule] -> ShowS
$cshowList :: [MaxCountRule] -> ShowS
show :: MaxCountRule -> String
$cshow :: MaxCountRule -> String
showsPrec :: Int -> MaxCountRule -> ShowS
$cshowsPrec :: Int -> MaxCountRule -> ShowS
Prelude.Show, forall x. Rep MaxCountRule x -> MaxCountRule
forall x. MaxCountRule -> Rep MaxCountRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MaxCountRule x -> MaxCountRule
$cfrom :: forall x. MaxCountRule -> Rep MaxCountRule x
Prelude.Generic)

-- |
-- Create a value of 'MaxCountRule' 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:
--
-- 'deleteSourceFromS3', 'maxCountRule_deleteSourceFromS3' - Set to @true@ to delete a version\'s source bundle from Amazon S3 when
-- Elastic Beanstalk deletes the application version.
--
-- 'maxCount', 'maxCountRule_maxCount' - Specify the maximum number of application versions to retain.
--
-- 'enabled', 'maxCountRule_enabled' - Specify @true@ to apply the rule, or @false@ to disable it.
newMaxCountRule ::
  -- | 'enabled'
  Prelude.Bool ->
  MaxCountRule
newMaxCountRule :: Bool -> MaxCountRule
newMaxCountRule Bool
pEnabled_ =
  MaxCountRule'
    { $sel:deleteSourceFromS3:MaxCountRule' :: Maybe Bool
deleteSourceFromS3 = forall a. Maybe a
Prelude.Nothing,
      $sel:maxCount:MaxCountRule' :: Maybe Int
maxCount = forall a. Maybe a
Prelude.Nothing,
      $sel:enabled:MaxCountRule' :: Bool
enabled = Bool
pEnabled_
    }

-- | Set to @true@ to delete a version\'s source bundle from Amazon S3 when
-- Elastic Beanstalk deletes the application version.
maxCountRule_deleteSourceFromS3 :: Lens.Lens' MaxCountRule (Prelude.Maybe Prelude.Bool)
maxCountRule_deleteSourceFromS3 :: Lens' MaxCountRule (Maybe Bool)
maxCountRule_deleteSourceFromS3 = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MaxCountRule' {Maybe Bool
deleteSourceFromS3 :: Maybe Bool
$sel:deleteSourceFromS3:MaxCountRule' :: MaxCountRule -> Maybe Bool
deleteSourceFromS3} -> Maybe Bool
deleteSourceFromS3) (\s :: MaxCountRule
s@MaxCountRule' {} Maybe Bool
a -> MaxCountRule
s {$sel:deleteSourceFromS3:MaxCountRule' :: Maybe Bool
deleteSourceFromS3 = Maybe Bool
a} :: MaxCountRule)

-- | Specify the maximum number of application versions to retain.
maxCountRule_maxCount :: Lens.Lens' MaxCountRule (Prelude.Maybe Prelude.Int)
maxCountRule_maxCount :: Lens' MaxCountRule (Maybe Int)
maxCountRule_maxCount = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MaxCountRule' {Maybe Int
maxCount :: Maybe Int
$sel:maxCount:MaxCountRule' :: MaxCountRule -> Maybe Int
maxCount} -> Maybe Int
maxCount) (\s :: MaxCountRule
s@MaxCountRule' {} Maybe Int
a -> MaxCountRule
s {$sel:maxCount:MaxCountRule' :: Maybe Int
maxCount = Maybe Int
a} :: MaxCountRule)

-- | Specify @true@ to apply the rule, or @false@ to disable it.
maxCountRule_enabled :: Lens.Lens' MaxCountRule Prelude.Bool
maxCountRule_enabled :: Lens' MaxCountRule Bool
maxCountRule_enabled = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MaxCountRule' {Bool
enabled :: Bool
$sel:enabled:MaxCountRule' :: MaxCountRule -> Bool
enabled} -> Bool
enabled) (\s :: MaxCountRule
s@MaxCountRule' {} Bool
a -> MaxCountRule
s {$sel:enabled:MaxCountRule' :: Bool
enabled = Bool
a} :: MaxCountRule)

instance Data.FromXML MaxCountRule where
  parseXML :: [Node] -> Either String MaxCountRule
parseXML [Node]
x =
    Maybe Bool -> Maybe Int -> Bool -> MaxCountRule
MaxCountRule'
      forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"DeleteSourceFromS3")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"MaxCount")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String a
Data..@ Text
"Enabled")

instance Prelude.Hashable MaxCountRule where
  hashWithSalt :: Int -> MaxCountRule -> Int
hashWithSalt Int
_salt MaxCountRule' {Bool
Maybe Bool
Maybe Int
enabled :: Bool
maxCount :: Maybe Int
deleteSourceFromS3 :: Maybe Bool
$sel:enabled:MaxCountRule' :: MaxCountRule -> Bool
$sel:maxCount:MaxCountRule' :: MaxCountRule -> Maybe Int
$sel:deleteSourceFromS3:MaxCountRule' :: MaxCountRule -> Maybe Bool
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
deleteSourceFromS3
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
maxCount
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Bool
enabled

instance Prelude.NFData MaxCountRule where
  rnf :: MaxCountRule -> ()
rnf MaxCountRule' {Bool
Maybe Bool
Maybe Int
enabled :: Bool
maxCount :: Maybe Int
deleteSourceFromS3 :: Maybe Bool
$sel:enabled:MaxCountRule' :: MaxCountRule -> Bool
$sel:maxCount:MaxCountRule' :: MaxCountRule -> Maybe Int
$sel:deleteSourceFromS3:MaxCountRule' :: MaxCountRule -> Maybe Bool
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
deleteSourceFromS3
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Int
maxCount
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Bool
enabled

instance Data.ToQuery MaxCountRule where
  toQuery :: MaxCountRule -> QueryString
toQuery MaxCountRule' {Bool
Maybe Bool
Maybe Int
enabled :: Bool
maxCount :: Maybe Int
deleteSourceFromS3 :: Maybe Bool
$sel:enabled:MaxCountRule' :: MaxCountRule -> Bool
$sel:maxCount:MaxCountRule' :: MaxCountRule -> Maybe Int
$sel:deleteSourceFromS3:MaxCountRule' :: MaxCountRule -> Maybe Bool
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"DeleteSourceFromS3" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Bool
deleteSourceFromS3,
        ByteString
"MaxCount" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Int
maxCount,
        ByteString
"Enabled" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Bool
enabled
      ]