{-# 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.RetentionArchiveTier
-- 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.RetentionArchiveTier 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

-- | __[Snapshot policies only]__ Describes the retention rule for archived
-- snapshots. Once the archive retention threshold is met, the snapshots
-- are permanently deleted from the archive tier.
--
-- The archive retention rule must retain snapshots in the archive tier for
-- a minimum of 90 days.
--
-- For __count-based schedules__, you must specify __Count__. For
-- __age-based schedules__, you must specify __Interval__ and
-- __IntervalUnit__.
--
-- For more information about using snapshot archiving, see
-- <https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/snapshot-ami-policy.html#dlm-archive Considerations for snapshot lifecycle policies>.
--
-- /See:/ 'newRetentionArchiveTier' smart constructor.
data RetentionArchiveTier = RetentionArchiveTier'
  { -- | The maximum number of snapshots to retain in the archive storage tier
    -- for each volume. The count must ensure that each snapshot remains in the
    -- archive tier for at least 90 days. For example, if the schedule creates
    -- snapshots every 30 days, you must specify a count of 3 or more to ensure
    -- that each snapshot is archived for at least 90 days.
    RetentionArchiveTier -> Maybe Natural
count :: Prelude.Maybe Prelude.Natural,
    -- | Specifies the period of time to retain snapshots in the archive tier.
    -- After this period expires, the snapshot is permanently deleted.
    RetentionArchiveTier -> Maybe Natural
interval :: Prelude.Maybe Prelude.Natural,
    -- | The unit of time in which to measure the __Interval__. For example, to
    -- retain a snapshots in the archive tier for 6 months, specify
    -- @Interval=6@ and @IntervalUnit=MONTHS@.
    RetentionArchiveTier -> Maybe RetentionIntervalUnitValues
intervalUnit :: Prelude.Maybe RetentionIntervalUnitValues
  }
  deriving (RetentionArchiveTier -> RetentionArchiveTier -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RetentionArchiveTier -> RetentionArchiveTier -> Bool
$c/= :: RetentionArchiveTier -> RetentionArchiveTier -> Bool
== :: RetentionArchiveTier -> RetentionArchiveTier -> Bool
$c== :: RetentionArchiveTier -> RetentionArchiveTier -> Bool
Prelude.Eq, ReadPrec [RetentionArchiveTier]
ReadPrec RetentionArchiveTier
Int -> ReadS RetentionArchiveTier
ReadS [RetentionArchiveTier]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RetentionArchiveTier]
$creadListPrec :: ReadPrec [RetentionArchiveTier]
readPrec :: ReadPrec RetentionArchiveTier
$creadPrec :: ReadPrec RetentionArchiveTier
readList :: ReadS [RetentionArchiveTier]
$creadList :: ReadS [RetentionArchiveTier]
readsPrec :: Int -> ReadS RetentionArchiveTier
$creadsPrec :: Int -> ReadS RetentionArchiveTier
Prelude.Read, Int -> RetentionArchiveTier -> ShowS
[RetentionArchiveTier] -> ShowS
RetentionArchiveTier -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RetentionArchiveTier] -> ShowS
$cshowList :: [RetentionArchiveTier] -> ShowS
show :: RetentionArchiveTier -> String
$cshow :: RetentionArchiveTier -> String
showsPrec :: Int -> RetentionArchiveTier -> ShowS
$cshowsPrec :: Int -> RetentionArchiveTier -> ShowS
Prelude.Show, forall x. Rep RetentionArchiveTier x -> RetentionArchiveTier
forall x. RetentionArchiveTier -> Rep RetentionArchiveTier x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RetentionArchiveTier x -> RetentionArchiveTier
$cfrom :: forall x. RetentionArchiveTier -> Rep RetentionArchiveTier x
Prelude.Generic)

-- |
-- Create a value of 'RetentionArchiveTier' 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', 'retentionArchiveTier_count' - The maximum number of snapshots to retain in the archive storage tier
-- for each volume. The count must ensure that each snapshot remains in the
-- archive tier for at least 90 days. For example, if the schedule creates
-- snapshots every 30 days, you must specify a count of 3 or more to ensure
-- that each snapshot is archived for at least 90 days.
--
-- 'interval', 'retentionArchiveTier_interval' - Specifies the period of time to retain snapshots in the archive tier.
-- After this period expires, the snapshot is permanently deleted.
--
-- 'intervalUnit', 'retentionArchiveTier_intervalUnit' - The unit of time in which to measure the __Interval__. For example, to
-- retain a snapshots in the archive tier for 6 months, specify
-- @Interval=6@ and @IntervalUnit=MONTHS@.
newRetentionArchiveTier ::
  RetentionArchiveTier
newRetentionArchiveTier :: RetentionArchiveTier
newRetentionArchiveTier =
  RetentionArchiveTier'
    { $sel:count:RetentionArchiveTier' :: Maybe Natural
count = forall a. Maybe a
Prelude.Nothing,
      $sel:interval:RetentionArchiveTier' :: Maybe Natural
interval = forall a. Maybe a
Prelude.Nothing,
      $sel:intervalUnit:RetentionArchiveTier' :: Maybe RetentionIntervalUnitValues
intervalUnit = forall a. Maybe a
Prelude.Nothing
    }

-- | The maximum number of snapshots to retain in the archive storage tier
-- for each volume. The count must ensure that each snapshot remains in the
-- archive tier for at least 90 days. For example, if the schedule creates
-- snapshots every 30 days, you must specify a count of 3 or more to ensure
-- that each snapshot is archived for at least 90 days.
retentionArchiveTier_count :: Lens.Lens' RetentionArchiveTier (Prelude.Maybe Prelude.Natural)
retentionArchiveTier_count :: Lens' RetentionArchiveTier (Maybe Natural)
retentionArchiveTier_count = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RetentionArchiveTier' {Maybe Natural
count :: Maybe Natural
$sel:count:RetentionArchiveTier' :: RetentionArchiveTier -> Maybe Natural
count} -> Maybe Natural
count) (\s :: RetentionArchiveTier
s@RetentionArchiveTier' {} Maybe Natural
a -> RetentionArchiveTier
s {$sel:count:RetentionArchiveTier' :: Maybe Natural
count = Maybe Natural
a} :: RetentionArchiveTier)

-- | Specifies the period of time to retain snapshots in the archive tier.
-- After this period expires, the snapshot is permanently deleted.
retentionArchiveTier_interval :: Lens.Lens' RetentionArchiveTier (Prelude.Maybe Prelude.Natural)
retentionArchiveTier_interval :: Lens' RetentionArchiveTier (Maybe Natural)
retentionArchiveTier_interval = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RetentionArchiveTier' {Maybe Natural
interval :: Maybe Natural
$sel:interval:RetentionArchiveTier' :: RetentionArchiveTier -> Maybe Natural
interval} -> Maybe Natural
interval) (\s :: RetentionArchiveTier
s@RetentionArchiveTier' {} Maybe Natural
a -> RetentionArchiveTier
s {$sel:interval:RetentionArchiveTier' :: Maybe Natural
interval = Maybe Natural
a} :: RetentionArchiveTier)

-- | The unit of time in which to measure the __Interval__. For example, to
-- retain a snapshots in the archive tier for 6 months, specify
-- @Interval=6@ and @IntervalUnit=MONTHS@.
retentionArchiveTier_intervalUnit :: Lens.Lens' RetentionArchiveTier (Prelude.Maybe RetentionIntervalUnitValues)
retentionArchiveTier_intervalUnit :: Lens' RetentionArchiveTier (Maybe RetentionIntervalUnitValues)
retentionArchiveTier_intervalUnit = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RetentionArchiveTier' {Maybe RetentionIntervalUnitValues
intervalUnit :: Maybe RetentionIntervalUnitValues
$sel:intervalUnit:RetentionArchiveTier' :: RetentionArchiveTier -> Maybe RetentionIntervalUnitValues
intervalUnit} -> Maybe RetentionIntervalUnitValues
intervalUnit) (\s :: RetentionArchiveTier
s@RetentionArchiveTier' {} Maybe RetentionIntervalUnitValues
a -> RetentionArchiveTier
s {$sel:intervalUnit:RetentionArchiveTier' :: Maybe RetentionIntervalUnitValues
intervalUnit = Maybe RetentionIntervalUnitValues
a} :: RetentionArchiveTier)

instance Data.FromJSON RetentionArchiveTier where
  parseJSON :: Value -> Parser RetentionArchiveTier
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"RetentionArchiveTier"
      ( \Object
x ->
          Maybe Natural
-> Maybe Natural
-> Maybe RetentionIntervalUnitValues
-> RetentionArchiveTier
RetentionArchiveTier'
            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 RetentionArchiveTier where
  hashWithSalt :: Int -> RetentionArchiveTier -> Int
hashWithSalt Int
_salt RetentionArchiveTier' {Maybe Natural
Maybe RetentionIntervalUnitValues
intervalUnit :: Maybe RetentionIntervalUnitValues
interval :: Maybe Natural
count :: Maybe Natural
$sel:intervalUnit:RetentionArchiveTier' :: RetentionArchiveTier -> Maybe RetentionIntervalUnitValues
$sel:interval:RetentionArchiveTier' :: RetentionArchiveTier -> Maybe Natural
$sel:count:RetentionArchiveTier' :: RetentionArchiveTier -> 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 RetentionArchiveTier where
  rnf :: RetentionArchiveTier -> ()
rnf RetentionArchiveTier' {Maybe Natural
Maybe RetentionIntervalUnitValues
intervalUnit :: Maybe RetentionIntervalUnitValues
interval :: Maybe Natural
count :: Maybe Natural
$sel:intervalUnit:RetentionArchiveTier' :: RetentionArchiveTier -> Maybe RetentionIntervalUnitValues
$sel:interval:RetentionArchiveTier' :: RetentionArchiveTier -> Maybe Natural
$sel:count:RetentionArchiveTier' :: RetentionArchiveTier -> 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 RetentionArchiveTier where
  toJSON :: RetentionArchiveTier -> Value
toJSON RetentionArchiveTier' {Maybe Natural
Maybe RetentionIntervalUnitValues
intervalUnit :: Maybe RetentionIntervalUnitValues
interval :: Maybe Natural
count :: Maybe Natural
$sel:intervalUnit:RetentionArchiveTier' :: RetentionArchiveTier -> Maybe RetentionIntervalUnitValues
$sel:interval:RetentionArchiveTier' :: RetentionArchiveTier -> Maybe Natural
$sel:count:RetentionArchiveTier' :: RetentionArchiveTier -> 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
          ]
      )