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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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'
  { -- | Specify the maximum number of application versions to retain.
    MaxCountRule -> Maybe Int
maxCount :: Prelude.Maybe Prelude.Int,
    -- | 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 @true@ to apply the rule, or @false@ to disable it.
    MaxCountRule -> Bool
enabled :: Prelude.Bool
  }
  deriving (MaxCountRule -> MaxCountRule -> Bool
(MaxCountRule -> MaxCountRule -> Bool)
-> (MaxCountRule -> MaxCountRule -> Bool) -> Eq MaxCountRule
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]
(Int -> ReadS MaxCountRule)
-> ReadS [MaxCountRule]
-> ReadPrec MaxCountRule
-> ReadPrec [MaxCountRule]
-> Read 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
(Int -> MaxCountRule -> ShowS)
-> (MaxCountRule -> String)
-> ([MaxCountRule] -> ShowS)
-> Show MaxCountRule
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. MaxCountRule -> Rep MaxCountRule x)
-> (forall x. Rep MaxCountRule x -> MaxCountRule)
-> Generic MaxCountRule
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:
--
-- 'maxCount', 'maxCountRule_maxCount' - Specify the maximum number of application versions to retain.
--
-- 'deleteSourceFromS3', 'maxCountRule_deleteSourceFromS3' - Set to @true@ to delete a version\'s source bundle from Amazon S3 when
-- Elastic Beanstalk deletes the application version.
--
-- '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' :: Maybe Int -> Maybe Bool -> Bool -> MaxCountRule
MaxCountRule'
    { $sel:maxCount:MaxCountRule' :: Maybe Int
maxCount = Maybe Int
forall a. Maybe a
Prelude.Nothing,
      $sel:deleteSourceFromS3:MaxCountRule' :: Maybe Bool
deleteSourceFromS3 = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:enabled:MaxCountRule' :: Bool
enabled = Bool
pEnabled_
    }

-- | Specify the maximum number of application versions to retain.
maxCountRule_maxCount :: Lens.Lens' MaxCountRule (Prelude.Maybe Prelude.Int)
maxCountRule_maxCount :: (Maybe Int -> f (Maybe Int)) -> MaxCountRule -> f MaxCountRule
maxCountRule_maxCount = (MaxCountRule -> Maybe Int)
-> (MaxCountRule -> Maybe Int -> MaxCountRule)
-> Lens MaxCountRule MaxCountRule (Maybe Int) (Maybe Int)
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)

-- | 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 :: (Maybe Bool -> f (Maybe Bool)) -> MaxCountRule -> f MaxCountRule
maxCountRule_deleteSourceFromS3 = (MaxCountRule -> Maybe Bool)
-> (MaxCountRule -> Maybe Bool -> MaxCountRule)
-> Lens MaxCountRule MaxCountRule (Maybe Bool) (Maybe Bool)
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 @true@ to apply the rule, or @false@ to disable it.
maxCountRule_enabled :: Lens.Lens' MaxCountRule Prelude.Bool
maxCountRule_enabled :: (Bool -> f Bool) -> MaxCountRule -> f MaxCountRule
maxCountRule_enabled = (MaxCountRule -> Bool)
-> (MaxCountRule -> Bool -> MaxCountRule)
-> Lens MaxCountRule MaxCountRule Bool Bool
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 Core.FromXML MaxCountRule where
  parseXML :: [Node] -> Either String MaxCountRule
parseXML [Node]
x =
    Maybe Int -> Maybe Bool -> Bool -> MaxCountRule
MaxCountRule'
      (Maybe Int -> Maybe Bool -> Bool -> MaxCountRule)
-> Either String (Maybe Int)
-> Either String (Maybe Bool -> Bool -> MaxCountRule)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe Int)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"MaxCount")
      Either String (Maybe Bool -> Bool -> MaxCountRule)
-> Either String (Maybe Bool)
-> Either String (Bool -> MaxCountRule)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Bool)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"DeleteSourceFromS3")
      Either String (Bool -> MaxCountRule)
-> Either String Bool -> Either String MaxCountRule
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Bool
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"Enabled")

instance Prelude.Hashable MaxCountRule

instance Prelude.NFData MaxCountRule

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