{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.DLM.Types.DeprecateRule where

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

-- | __[AMI policies only]__ Specifies an AMI deprecation rule for AMIs
-- created by an AMI lifecycle policy.
--
-- For age-based schedules, you must specify __Interval__ and
-- __IntervalUnit__. For count-based schedules, you must specify __Count__.
--
-- /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
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]
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
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. 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'
    { $sel:count:DeprecateRule' :: Maybe Natural
count = forall a. Maybe a
Prelude.Nothing,
      $sel:interval:DeprecateRule' :: Maybe Natural
interval = forall a. Maybe a
Prelude.Nothing,
      $sel:intervalUnit:DeprecateRule' :: Maybe RetentionIntervalUnitValues
intervalUnit = 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 :: Lens' DeprecateRule (Maybe Natural)
deprecateRule_count = 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 :: Lens' DeprecateRule (Maybe Natural)
deprecateRule_interval = 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 :: Lens' DeprecateRule (Maybe RetentionIntervalUnitValues)
deprecateRule_intervalUnit = 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 Data.FromJSON DeprecateRule where
  parseJSON :: Value -> Parser DeprecateRule
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"DeprecateRule"
      ( \Object
x ->
          Maybe Natural
-> Maybe Natural
-> Maybe RetentionIntervalUnitValues
-> DeprecateRule
DeprecateRule'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Count")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Interval")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"IntervalUnit")
      )

instance Prelude.Hashable DeprecateRule where
  hashWithSalt :: Int -> DeprecateRule -> Int
hashWithSalt Int
_salt 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
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
count
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
interval
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe RetentionIntervalUnitValues
intervalUnit

instance Prelude.NFData DeprecateRule where
  rnf :: DeprecateRule -> ()
rnf 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
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
count
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
interval
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe RetentionIntervalUnitValues
intervalUnit

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Count" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
count,
            (Key
"Interval" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
interval,
            (Key
"IntervalUnit" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe RetentionIntervalUnitValues
intervalUnit
          ]
      )