{-# 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.DLM.Types.DeprecateRule
-- 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.DLM.Types.DeprecateRule where

import qualified Amazonka.Core as Core
import Amazonka.DLM.Types.RetentionIntervalUnitValues
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Specifies an AMI deprecation rule for a schedule.
--
-- /See:/ 'newDeprecateRule' smart constructor.
data DeprecateRule = DeprecateRule'
  { -- | If the schedule has a count-based retention rule, this parameter
    -- specifies the number of oldest AMIs to deprecate. The count must be less
    -- than or equal to the schedule\'s retention count, and it can\'t be
    -- greater than 1000.
    DeprecateRule -> Maybe Natural
count :: Prelude.Maybe Prelude.Natural,
    -- | If the schedule has an age-based retention rule, this parameter
    -- specifies the period after which to deprecate AMIs created by the
    -- schedule. The period must be less than or equal to the schedule\'s
    -- retention period, and it can\'t be greater than 10 years. This is
    -- equivalent to 120 months, 520 weeks, or 3650 days.
    DeprecateRule -> Maybe Natural
interval :: Prelude.Maybe Prelude.Natural,
    -- | The unit of time in which to measure the __Interval__.
    DeprecateRule -> Maybe RetentionIntervalUnitValues
intervalUnit :: Prelude.Maybe RetentionIntervalUnitValues
  }
  deriving (DeprecateRule -> DeprecateRule -> Bool
(DeprecateRule -> DeprecateRule -> Bool)
-> (DeprecateRule -> DeprecateRule -> Bool) -> Eq DeprecateRule
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeprecateRule -> DeprecateRule -> Bool
$c/= :: DeprecateRule -> DeprecateRule -> Bool
== :: DeprecateRule -> DeprecateRule -> Bool
$c== :: DeprecateRule -> DeprecateRule -> Bool
Prelude.Eq, ReadPrec [DeprecateRule]
ReadPrec DeprecateRule
Int -> ReadS DeprecateRule
ReadS [DeprecateRule]
(Int -> ReadS DeprecateRule)
-> ReadS [DeprecateRule]
-> ReadPrec DeprecateRule
-> ReadPrec [DeprecateRule]
-> Read DeprecateRule
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeprecateRule]
$creadListPrec :: ReadPrec [DeprecateRule]
readPrec :: ReadPrec DeprecateRule
$creadPrec :: ReadPrec DeprecateRule
readList :: ReadS [DeprecateRule]
$creadList :: ReadS [DeprecateRule]
readsPrec :: Int -> ReadS DeprecateRule
$creadsPrec :: Int -> ReadS DeprecateRule
Prelude.Read, Int -> DeprecateRule -> ShowS
[DeprecateRule] -> ShowS
DeprecateRule -> String
(Int -> DeprecateRule -> ShowS)
-> (DeprecateRule -> String)
-> ([DeprecateRule] -> ShowS)
-> Show DeprecateRule
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeprecateRule] -> ShowS
$cshowList :: [DeprecateRule] -> ShowS
show :: DeprecateRule -> String
$cshow :: DeprecateRule -> String
showsPrec :: Int -> DeprecateRule -> ShowS
$cshowsPrec :: Int -> DeprecateRule -> ShowS
Prelude.Show, (forall x. DeprecateRule -> Rep DeprecateRule x)
-> (forall x. Rep DeprecateRule x -> DeprecateRule)
-> Generic DeprecateRule
forall x. Rep DeprecateRule x -> DeprecateRule
forall x. DeprecateRule -> Rep DeprecateRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeprecateRule x -> DeprecateRule
$cfrom :: forall x. DeprecateRule -> Rep DeprecateRule x
Prelude.Generic)

-- |
-- Create a value of 'DeprecateRule' 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:
--
-- 'count', 'deprecateRule_count' - If the schedule has a count-based retention rule, this parameter
-- specifies the number of oldest AMIs to deprecate. The count must be less
-- than or equal to the schedule\'s retention count, and it can\'t be
-- greater than 1000.
--
-- 'interval', 'deprecateRule_interval' - If the schedule has an age-based retention rule, this parameter
-- specifies the period after which to deprecate AMIs created by the
-- schedule. The period must be less than or equal to the schedule\'s
-- retention period, and it can\'t be greater than 10 years. This is
-- equivalent to 120 months, 520 weeks, or 3650 days.
--
-- 'intervalUnit', 'deprecateRule_intervalUnit' - The unit of time in which to measure the __Interval__.
newDeprecateRule ::
  DeprecateRule
newDeprecateRule :: DeprecateRule
newDeprecateRule =
  DeprecateRule' :: Maybe Natural
-> Maybe Natural
-> Maybe RetentionIntervalUnitValues
-> DeprecateRule
DeprecateRule'
    { $sel:count:DeprecateRule' :: Maybe Natural
count = Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:interval:DeprecateRule' :: Maybe Natural
interval = Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:intervalUnit:DeprecateRule' :: Maybe RetentionIntervalUnitValues
intervalUnit = Maybe RetentionIntervalUnitValues
forall a. Maybe a
Prelude.Nothing
    }

-- | If the schedule has a count-based retention rule, this parameter
-- specifies the number of oldest AMIs to deprecate. The count must be less
-- than or equal to the schedule\'s retention count, and it can\'t be
-- greater than 1000.
deprecateRule_count :: Lens.Lens' DeprecateRule (Prelude.Maybe Prelude.Natural)
deprecateRule_count :: (Maybe Natural -> f (Maybe Natural))
-> DeprecateRule -> f DeprecateRule
deprecateRule_count = (DeprecateRule -> Maybe Natural)
-> (DeprecateRule -> Maybe Natural -> DeprecateRule)
-> Lens DeprecateRule DeprecateRule (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeprecateRule' {Maybe Natural
count :: Maybe Natural
$sel:count:DeprecateRule' :: DeprecateRule -> Maybe Natural
count} -> Maybe Natural
count) (\s :: DeprecateRule
s@DeprecateRule' {} Maybe Natural
a -> DeprecateRule
s {$sel:count:DeprecateRule' :: Maybe Natural
count = Maybe Natural
a} :: DeprecateRule)

-- | If the schedule has an age-based retention rule, this parameter
-- specifies the period after which to deprecate AMIs created by the
-- schedule. The period must be less than or equal to the schedule\'s
-- retention period, and it can\'t be greater than 10 years. This is
-- equivalent to 120 months, 520 weeks, or 3650 days.
deprecateRule_interval :: Lens.Lens' DeprecateRule (Prelude.Maybe Prelude.Natural)
deprecateRule_interval :: (Maybe Natural -> f (Maybe Natural))
-> DeprecateRule -> f DeprecateRule
deprecateRule_interval = (DeprecateRule -> Maybe Natural)
-> (DeprecateRule -> Maybe Natural -> DeprecateRule)
-> Lens DeprecateRule DeprecateRule (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeprecateRule' {Maybe Natural
interval :: Maybe Natural
$sel:interval:DeprecateRule' :: DeprecateRule -> Maybe Natural
interval} -> Maybe Natural
interval) (\s :: DeprecateRule
s@DeprecateRule' {} Maybe Natural
a -> DeprecateRule
s {$sel:interval:DeprecateRule' :: Maybe Natural
interval = Maybe Natural
a} :: DeprecateRule)

-- | The unit of time in which to measure the __Interval__.
deprecateRule_intervalUnit :: Lens.Lens' DeprecateRule (Prelude.Maybe RetentionIntervalUnitValues)
deprecateRule_intervalUnit :: (Maybe RetentionIntervalUnitValues
 -> f (Maybe RetentionIntervalUnitValues))
-> DeprecateRule -> f DeprecateRule
deprecateRule_intervalUnit = (DeprecateRule -> Maybe RetentionIntervalUnitValues)
-> (DeprecateRule
    -> Maybe RetentionIntervalUnitValues -> DeprecateRule)
-> Lens
     DeprecateRule
     DeprecateRule
     (Maybe RetentionIntervalUnitValues)
     (Maybe RetentionIntervalUnitValues)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeprecateRule' {Maybe RetentionIntervalUnitValues
intervalUnit :: Maybe RetentionIntervalUnitValues
$sel:intervalUnit:DeprecateRule' :: DeprecateRule -> Maybe RetentionIntervalUnitValues
intervalUnit} -> Maybe RetentionIntervalUnitValues
intervalUnit) (\s :: DeprecateRule
s@DeprecateRule' {} Maybe RetentionIntervalUnitValues
a -> DeprecateRule
s {$sel:intervalUnit:DeprecateRule' :: Maybe RetentionIntervalUnitValues
intervalUnit = Maybe RetentionIntervalUnitValues
a} :: DeprecateRule)

instance Core.FromJSON DeprecateRule where
  parseJSON :: Value -> Parser DeprecateRule
parseJSON =
    String
-> (Object -> Parser DeprecateRule)
-> Value
-> Parser DeprecateRule
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"DeprecateRule"
      ( \Object
x ->
          Maybe Natural
-> Maybe Natural
-> Maybe RetentionIntervalUnitValues
-> DeprecateRule
DeprecateRule'
            (Maybe Natural
 -> Maybe Natural
 -> Maybe RetentionIntervalUnitValues
 -> DeprecateRule)
-> Parser (Maybe Natural)
-> Parser
     (Maybe Natural
      -> Maybe RetentionIntervalUnitValues -> DeprecateRule)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Natural)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Count")
            Parser
  (Maybe Natural
   -> Maybe RetentionIntervalUnitValues -> DeprecateRule)
-> Parser (Maybe Natural)
-> Parser (Maybe RetentionIntervalUnitValues -> DeprecateRule)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Natural)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Interval")
            Parser (Maybe RetentionIntervalUnitValues -> DeprecateRule)
-> Parser (Maybe RetentionIntervalUnitValues)
-> Parser DeprecateRule
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe RetentionIntervalUnitValues)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"IntervalUnit")
      )

instance Prelude.Hashable DeprecateRule

instance Prelude.NFData DeprecateRule

instance Core.ToJSON DeprecateRule where
  toJSON :: DeprecateRule -> Value
toJSON DeprecateRule' {Maybe Natural
Maybe RetentionIntervalUnitValues
intervalUnit :: Maybe RetentionIntervalUnitValues
interval :: Maybe Natural
count :: Maybe Natural
$sel:intervalUnit:DeprecateRule' :: DeprecateRule -> Maybe RetentionIntervalUnitValues
$sel:interval:DeprecateRule' :: DeprecateRule -> Maybe Natural
$sel:count:DeprecateRule' :: DeprecateRule -> Maybe Natural
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Count" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
count,
            (Text
"Interval" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
interval,
            (Text
"IntervalUnit" Text -> RetentionIntervalUnitValues -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (RetentionIntervalUnitValues -> Pair)
-> Maybe RetentionIntervalUnitValues -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe RetentionIntervalUnitValues
intervalUnit
          ]
      )