{-# 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.MaxAgeRule
-- 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.MaxAgeRule where

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

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

-- |
-- Create a value of 'MaxAgeRule' 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', 'maxAgeRule_deleteSourceFromS3' - Set to @true@ to delete a version\'s source bundle from Amazon S3 when
-- Elastic Beanstalk deletes the application version.
--
-- 'maxAgeInDays', 'maxAgeRule_maxAgeInDays' - Specify the number of days to retain an application versions.
--
-- 'enabled', 'maxAgeRule_enabled' - Specify @true@ to apply the rule, or @false@ to disable it.
newMaxAgeRule ::
  -- | 'enabled'
  Prelude.Bool ->
  MaxAgeRule
newMaxAgeRule :: Bool -> MaxAgeRule
newMaxAgeRule Bool
pEnabled_ =
  MaxAgeRule' :: Maybe Bool -> Maybe Int -> Bool -> MaxAgeRule
MaxAgeRule'
    { $sel:deleteSourceFromS3:MaxAgeRule' :: Maybe Bool
deleteSourceFromS3 = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:maxAgeInDays:MaxAgeRule' :: Maybe Int
maxAgeInDays = Maybe Int
forall a. Maybe a
Prelude.Nothing,
      $sel:enabled:MaxAgeRule' :: Bool
enabled = Bool
pEnabled_
    }

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

-- | Specify the number of days to retain an application versions.
maxAgeRule_maxAgeInDays :: Lens.Lens' MaxAgeRule (Prelude.Maybe Prelude.Int)
maxAgeRule_maxAgeInDays :: (Maybe Int -> f (Maybe Int)) -> MaxAgeRule -> f MaxAgeRule
maxAgeRule_maxAgeInDays = (MaxAgeRule -> Maybe Int)
-> (MaxAgeRule -> Maybe Int -> MaxAgeRule)
-> Lens MaxAgeRule MaxAgeRule (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MaxAgeRule' {Maybe Int
maxAgeInDays :: Maybe Int
$sel:maxAgeInDays:MaxAgeRule' :: MaxAgeRule -> Maybe Int
maxAgeInDays} -> Maybe Int
maxAgeInDays) (\s :: MaxAgeRule
s@MaxAgeRule' {} Maybe Int
a -> MaxAgeRule
s {$sel:maxAgeInDays:MaxAgeRule' :: Maybe Int
maxAgeInDays = Maybe Int
a} :: MaxAgeRule)

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

instance Core.FromXML MaxAgeRule where
  parseXML :: [Node] -> Either String MaxAgeRule
parseXML [Node]
x =
    Maybe Bool -> Maybe Int -> Bool -> MaxAgeRule
MaxAgeRule'
      (Maybe Bool -> Maybe Int -> Bool -> MaxAgeRule)
-> Either String (Maybe Bool)
-> Either String (Maybe Int -> Bool -> MaxAgeRule)
forall (f :: * -> *) a b. Functor 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 (Maybe Int -> Bool -> MaxAgeRule)
-> Either String (Maybe Int) -> Either String (Bool -> MaxAgeRule)
forall (f :: * -> *) a b. Applicative f => 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
"MaxAgeInDays")
      Either String (Bool -> MaxAgeRule)
-> Either String Bool -> Either String MaxAgeRule
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 MaxAgeRule

instance Prelude.NFData MaxAgeRule

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