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

import qualified Amazonka.Core as Core
import Amazonka.ElasticBeanstalk.Types.MaxAgeRule
import Amazonka.ElasticBeanstalk.Types.MaxCountRule
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The application version lifecycle settings for an application. Defines
-- the rules that Elastic Beanstalk applies to an application\'s versions
-- in order to avoid hitting the per-region limit for application versions.
--
-- When Elastic Beanstalk deletes an application version from its database,
-- you can no longer deploy that version to an environment. The source
-- bundle remains in S3 unless you configure the rule to delete it.
--
-- /See:/ 'newApplicationVersionLifecycleConfig' smart constructor.
data ApplicationVersionLifecycleConfig = ApplicationVersionLifecycleConfig'
  { -- | Specify a max age rule to restrict the length of time that application
    -- versions are retained for an application.
    ApplicationVersionLifecycleConfig -> Maybe MaxAgeRule
maxAgeRule :: Prelude.Maybe MaxAgeRule,
    -- | Specify a max count rule to restrict the number of application versions
    -- that are retained for an application.
    ApplicationVersionLifecycleConfig -> Maybe MaxCountRule
maxCountRule :: Prelude.Maybe MaxCountRule
  }
  deriving (ApplicationVersionLifecycleConfig
-> ApplicationVersionLifecycleConfig -> Bool
(ApplicationVersionLifecycleConfig
 -> ApplicationVersionLifecycleConfig -> Bool)
-> (ApplicationVersionLifecycleConfig
    -> ApplicationVersionLifecycleConfig -> Bool)
-> Eq ApplicationVersionLifecycleConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ApplicationVersionLifecycleConfig
-> ApplicationVersionLifecycleConfig -> Bool
$c/= :: ApplicationVersionLifecycleConfig
-> ApplicationVersionLifecycleConfig -> Bool
== :: ApplicationVersionLifecycleConfig
-> ApplicationVersionLifecycleConfig -> Bool
$c== :: ApplicationVersionLifecycleConfig
-> ApplicationVersionLifecycleConfig -> Bool
Prelude.Eq, ReadPrec [ApplicationVersionLifecycleConfig]
ReadPrec ApplicationVersionLifecycleConfig
Int -> ReadS ApplicationVersionLifecycleConfig
ReadS [ApplicationVersionLifecycleConfig]
(Int -> ReadS ApplicationVersionLifecycleConfig)
-> ReadS [ApplicationVersionLifecycleConfig]
-> ReadPrec ApplicationVersionLifecycleConfig
-> ReadPrec [ApplicationVersionLifecycleConfig]
-> Read ApplicationVersionLifecycleConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ApplicationVersionLifecycleConfig]
$creadListPrec :: ReadPrec [ApplicationVersionLifecycleConfig]
readPrec :: ReadPrec ApplicationVersionLifecycleConfig
$creadPrec :: ReadPrec ApplicationVersionLifecycleConfig
readList :: ReadS [ApplicationVersionLifecycleConfig]
$creadList :: ReadS [ApplicationVersionLifecycleConfig]
readsPrec :: Int -> ReadS ApplicationVersionLifecycleConfig
$creadsPrec :: Int -> ReadS ApplicationVersionLifecycleConfig
Prelude.Read, Int -> ApplicationVersionLifecycleConfig -> ShowS
[ApplicationVersionLifecycleConfig] -> ShowS
ApplicationVersionLifecycleConfig -> String
(Int -> ApplicationVersionLifecycleConfig -> ShowS)
-> (ApplicationVersionLifecycleConfig -> String)
-> ([ApplicationVersionLifecycleConfig] -> ShowS)
-> Show ApplicationVersionLifecycleConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ApplicationVersionLifecycleConfig] -> ShowS
$cshowList :: [ApplicationVersionLifecycleConfig] -> ShowS
show :: ApplicationVersionLifecycleConfig -> String
$cshow :: ApplicationVersionLifecycleConfig -> String
showsPrec :: Int -> ApplicationVersionLifecycleConfig -> ShowS
$cshowsPrec :: Int -> ApplicationVersionLifecycleConfig -> ShowS
Prelude.Show, (forall x.
 ApplicationVersionLifecycleConfig
 -> Rep ApplicationVersionLifecycleConfig x)
-> (forall x.
    Rep ApplicationVersionLifecycleConfig x
    -> ApplicationVersionLifecycleConfig)
-> Generic ApplicationVersionLifecycleConfig
forall x.
Rep ApplicationVersionLifecycleConfig x
-> ApplicationVersionLifecycleConfig
forall x.
ApplicationVersionLifecycleConfig
-> Rep ApplicationVersionLifecycleConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ApplicationVersionLifecycleConfig x
-> ApplicationVersionLifecycleConfig
$cfrom :: forall x.
ApplicationVersionLifecycleConfig
-> Rep ApplicationVersionLifecycleConfig x
Prelude.Generic)

-- |
-- Create a value of 'ApplicationVersionLifecycleConfig' 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:
--
-- 'maxAgeRule', 'applicationVersionLifecycleConfig_maxAgeRule' - Specify a max age rule to restrict the length of time that application
-- versions are retained for an application.
--
-- 'maxCountRule', 'applicationVersionLifecycleConfig_maxCountRule' - Specify a max count rule to restrict the number of application versions
-- that are retained for an application.
newApplicationVersionLifecycleConfig ::
  ApplicationVersionLifecycleConfig
newApplicationVersionLifecycleConfig :: ApplicationVersionLifecycleConfig
newApplicationVersionLifecycleConfig =
  ApplicationVersionLifecycleConfig' :: Maybe MaxAgeRule
-> Maybe MaxCountRule -> ApplicationVersionLifecycleConfig
ApplicationVersionLifecycleConfig'
    { $sel:maxAgeRule:ApplicationVersionLifecycleConfig' :: Maybe MaxAgeRule
maxAgeRule =
        Maybe MaxAgeRule
forall a. Maybe a
Prelude.Nothing,
      $sel:maxCountRule:ApplicationVersionLifecycleConfig' :: Maybe MaxCountRule
maxCountRule = Maybe MaxCountRule
forall a. Maybe a
Prelude.Nothing
    }

-- | Specify a max age rule to restrict the length of time that application
-- versions are retained for an application.
applicationVersionLifecycleConfig_maxAgeRule :: Lens.Lens' ApplicationVersionLifecycleConfig (Prelude.Maybe MaxAgeRule)
applicationVersionLifecycleConfig_maxAgeRule :: (Maybe MaxAgeRule -> f (Maybe MaxAgeRule))
-> ApplicationVersionLifecycleConfig
-> f ApplicationVersionLifecycleConfig
applicationVersionLifecycleConfig_maxAgeRule = (ApplicationVersionLifecycleConfig -> Maybe MaxAgeRule)
-> (ApplicationVersionLifecycleConfig
    -> Maybe MaxAgeRule -> ApplicationVersionLifecycleConfig)
-> Lens
     ApplicationVersionLifecycleConfig
     ApplicationVersionLifecycleConfig
     (Maybe MaxAgeRule)
     (Maybe MaxAgeRule)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ApplicationVersionLifecycleConfig' {Maybe MaxAgeRule
maxAgeRule :: Maybe MaxAgeRule
$sel:maxAgeRule:ApplicationVersionLifecycleConfig' :: ApplicationVersionLifecycleConfig -> Maybe MaxAgeRule
maxAgeRule} -> Maybe MaxAgeRule
maxAgeRule) (\s :: ApplicationVersionLifecycleConfig
s@ApplicationVersionLifecycleConfig' {} Maybe MaxAgeRule
a -> ApplicationVersionLifecycleConfig
s {$sel:maxAgeRule:ApplicationVersionLifecycleConfig' :: Maybe MaxAgeRule
maxAgeRule = Maybe MaxAgeRule
a} :: ApplicationVersionLifecycleConfig)

-- | Specify a max count rule to restrict the number of application versions
-- that are retained for an application.
applicationVersionLifecycleConfig_maxCountRule :: Lens.Lens' ApplicationVersionLifecycleConfig (Prelude.Maybe MaxCountRule)
applicationVersionLifecycleConfig_maxCountRule :: (Maybe MaxCountRule -> f (Maybe MaxCountRule))
-> ApplicationVersionLifecycleConfig
-> f ApplicationVersionLifecycleConfig
applicationVersionLifecycleConfig_maxCountRule = (ApplicationVersionLifecycleConfig -> Maybe MaxCountRule)
-> (ApplicationVersionLifecycleConfig
    -> Maybe MaxCountRule -> ApplicationVersionLifecycleConfig)
-> Lens
     ApplicationVersionLifecycleConfig
     ApplicationVersionLifecycleConfig
     (Maybe MaxCountRule)
     (Maybe MaxCountRule)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ApplicationVersionLifecycleConfig' {Maybe MaxCountRule
maxCountRule :: Maybe MaxCountRule
$sel:maxCountRule:ApplicationVersionLifecycleConfig' :: ApplicationVersionLifecycleConfig -> Maybe MaxCountRule
maxCountRule} -> Maybe MaxCountRule
maxCountRule) (\s :: ApplicationVersionLifecycleConfig
s@ApplicationVersionLifecycleConfig' {} Maybe MaxCountRule
a -> ApplicationVersionLifecycleConfig
s {$sel:maxCountRule:ApplicationVersionLifecycleConfig' :: Maybe MaxCountRule
maxCountRule = Maybe MaxCountRule
a} :: ApplicationVersionLifecycleConfig)

instance
  Core.FromXML
    ApplicationVersionLifecycleConfig
  where
  parseXML :: [Node] -> Either String ApplicationVersionLifecycleConfig
parseXML [Node]
x =
    Maybe MaxAgeRule
-> Maybe MaxCountRule -> ApplicationVersionLifecycleConfig
ApplicationVersionLifecycleConfig'
      (Maybe MaxAgeRule
 -> Maybe MaxCountRule -> ApplicationVersionLifecycleConfig)
-> Either String (Maybe MaxAgeRule)
-> Either
     String (Maybe MaxCountRule -> ApplicationVersionLifecycleConfig)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe MaxAgeRule)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"MaxAgeRule")
      Either
  String (Maybe MaxCountRule -> ApplicationVersionLifecycleConfig)
-> Either String (Maybe MaxCountRule)
-> Either String ApplicationVersionLifecycleConfig
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe MaxCountRule)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"MaxCountRule")

instance
  Prelude.Hashable
    ApplicationVersionLifecycleConfig

instance
  Prelude.NFData
    ApplicationVersionLifecycleConfig

instance
  Core.ToQuery
    ApplicationVersionLifecycleConfig
  where
  toQuery :: ApplicationVersionLifecycleConfig -> QueryString
toQuery ApplicationVersionLifecycleConfig' {Maybe MaxAgeRule
Maybe MaxCountRule
maxCountRule :: Maybe MaxCountRule
maxAgeRule :: Maybe MaxAgeRule
$sel:maxCountRule:ApplicationVersionLifecycleConfig' :: ApplicationVersionLifecycleConfig -> Maybe MaxCountRule
$sel:maxAgeRule:ApplicationVersionLifecycleConfig' :: ApplicationVersionLifecycleConfig -> Maybe MaxAgeRule
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"MaxAgeRule" ByteString -> Maybe MaxAgeRule -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe MaxAgeRule
maxAgeRule,
        ByteString
"MaxCountRule" ByteString -> Maybe MaxCountRule -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe MaxCountRule
maxCountRule
      ]