{-# 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.Backup.Types.Lifecycle
-- 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.Backup.Types.Lifecycle where

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

-- | Contains an array of @Transition@ objects specifying how long in days
-- before a recovery point transitions to cold storage or is deleted.
--
-- Backups transitioned to cold storage must be stored in cold storage for
-- a minimum of 90 days. Therefore, on the console, the “retention” setting
-- must be 90 days greater than the “transition to cold after days”
-- setting. The “transition to cold after days” setting cannot be changed
-- after a backup has been transitioned to cold.
--
-- Resource types that are able to be transitioned to cold storage are
-- listed in the \"Lifecycle to cold storage\" section of the
-- <https://docs.aws.amazon.com/aws-backup/latest/devguide/whatisbackup.html#features-by-resource Feature availability by resource>
-- table. Backup ignores this expression for other resource types.
--
-- /See:/ 'newLifecycle' smart constructor.
data Lifecycle = Lifecycle'
  { -- | Specifies the number of days after creation that a recovery point is
    -- deleted. Must be greater than 90 days plus @MoveToColdStorageAfterDays@.
    Lifecycle -> Maybe Integer
deleteAfterDays :: Prelude.Maybe Prelude.Integer,
    -- | Specifies the number of days after creation that a recovery point is
    -- moved to cold storage.
    Lifecycle -> Maybe Integer
moveToColdStorageAfterDays :: Prelude.Maybe Prelude.Integer
  }
  deriving (Lifecycle -> Lifecycle -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Lifecycle -> Lifecycle -> Bool
$c/= :: Lifecycle -> Lifecycle -> Bool
== :: Lifecycle -> Lifecycle -> Bool
$c== :: Lifecycle -> Lifecycle -> Bool
Prelude.Eq, ReadPrec [Lifecycle]
ReadPrec Lifecycle
Int -> ReadS Lifecycle
ReadS [Lifecycle]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Lifecycle]
$creadListPrec :: ReadPrec [Lifecycle]
readPrec :: ReadPrec Lifecycle
$creadPrec :: ReadPrec Lifecycle
readList :: ReadS [Lifecycle]
$creadList :: ReadS [Lifecycle]
readsPrec :: Int -> ReadS Lifecycle
$creadsPrec :: Int -> ReadS Lifecycle
Prelude.Read, Int -> Lifecycle -> ShowS
[Lifecycle] -> ShowS
Lifecycle -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Lifecycle] -> ShowS
$cshowList :: [Lifecycle] -> ShowS
show :: Lifecycle -> String
$cshow :: Lifecycle -> String
showsPrec :: Int -> Lifecycle -> ShowS
$cshowsPrec :: Int -> Lifecycle -> ShowS
Prelude.Show, forall x. Rep Lifecycle x -> Lifecycle
forall x. Lifecycle -> Rep Lifecycle x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Lifecycle x -> Lifecycle
$cfrom :: forall x. Lifecycle -> Rep Lifecycle x
Prelude.Generic)

-- |
-- Create a value of 'Lifecycle' 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:
--
-- 'deleteAfterDays', 'lifecycle_deleteAfterDays' - Specifies the number of days after creation that a recovery point is
-- deleted. Must be greater than 90 days plus @MoveToColdStorageAfterDays@.
--
-- 'moveToColdStorageAfterDays', 'lifecycle_moveToColdStorageAfterDays' - Specifies the number of days after creation that a recovery point is
-- moved to cold storage.
newLifecycle ::
  Lifecycle
newLifecycle :: Lifecycle
newLifecycle =
  Lifecycle'
    { $sel:deleteAfterDays:Lifecycle' :: Maybe Integer
deleteAfterDays = forall a. Maybe a
Prelude.Nothing,
      $sel:moveToColdStorageAfterDays:Lifecycle' :: Maybe Integer
moveToColdStorageAfterDays = forall a. Maybe a
Prelude.Nothing
    }

-- | Specifies the number of days after creation that a recovery point is
-- deleted. Must be greater than 90 days plus @MoveToColdStorageAfterDays@.
lifecycle_deleteAfterDays :: Lens.Lens' Lifecycle (Prelude.Maybe Prelude.Integer)
lifecycle_deleteAfterDays :: Lens' Lifecycle (Maybe Integer)
lifecycle_deleteAfterDays = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Lifecycle' {Maybe Integer
deleteAfterDays :: Maybe Integer
$sel:deleteAfterDays:Lifecycle' :: Lifecycle -> Maybe Integer
deleteAfterDays} -> Maybe Integer
deleteAfterDays) (\s :: Lifecycle
s@Lifecycle' {} Maybe Integer
a -> Lifecycle
s {$sel:deleteAfterDays:Lifecycle' :: Maybe Integer
deleteAfterDays = Maybe Integer
a} :: Lifecycle)

-- | Specifies the number of days after creation that a recovery point is
-- moved to cold storage.
lifecycle_moveToColdStorageAfterDays :: Lens.Lens' Lifecycle (Prelude.Maybe Prelude.Integer)
lifecycle_moveToColdStorageAfterDays :: Lens' Lifecycle (Maybe Integer)
lifecycle_moveToColdStorageAfterDays = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Lifecycle' {Maybe Integer
moveToColdStorageAfterDays :: Maybe Integer
$sel:moveToColdStorageAfterDays:Lifecycle' :: Lifecycle -> Maybe Integer
moveToColdStorageAfterDays} -> Maybe Integer
moveToColdStorageAfterDays) (\s :: Lifecycle
s@Lifecycle' {} Maybe Integer
a -> Lifecycle
s {$sel:moveToColdStorageAfterDays:Lifecycle' :: Maybe Integer
moveToColdStorageAfterDays = Maybe Integer
a} :: Lifecycle)

instance Data.FromJSON Lifecycle where
  parseJSON :: Value -> Parser Lifecycle
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Lifecycle"
      ( \Object
x ->
          Maybe Integer -> Maybe Integer -> Lifecycle
Lifecycle'
            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
"DeleteAfterDays")
            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
"MoveToColdStorageAfterDays")
      )

instance Prelude.Hashable Lifecycle where
  hashWithSalt :: Int -> Lifecycle -> Int
hashWithSalt Int
_salt Lifecycle' {Maybe Integer
moveToColdStorageAfterDays :: Maybe Integer
deleteAfterDays :: Maybe Integer
$sel:moveToColdStorageAfterDays:Lifecycle' :: Lifecycle -> Maybe Integer
$sel:deleteAfterDays:Lifecycle' :: Lifecycle -> Maybe Integer
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Integer
deleteAfterDays
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Integer
moveToColdStorageAfterDays

instance Prelude.NFData Lifecycle where
  rnf :: Lifecycle -> ()
rnf Lifecycle' {Maybe Integer
moveToColdStorageAfterDays :: Maybe Integer
deleteAfterDays :: Maybe Integer
$sel:moveToColdStorageAfterDays:Lifecycle' :: Lifecycle -> Maybe Integer
$sel:deleteAfterDays:Lifecycle' :: Lifecycle -> Maybe Integer
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Integer
deleteAfterDays
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Integer
moveToColdStorageAfterDays

instance Data.ToJSON Lifecycle where
  toJSON :: Lifecycle -> Value
toJSON Lifecycle' {Maybe Integer
moveToColdStorageAfterDays :: Maybe Integer
deleteAfterDays :: Maybe Integer
$sel:moveToColdStorageAfterDays:Lifecycle' :: Lifecycle -> Maybe Integer
$sel:deleteAfterDays:Lifecycle' :: Lifecycle -> Maybe Integer
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"DeleteAfterDays" 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 Integer
deleteAfterDays,
            (Key
"MoveToColdStorageAfterDays" 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 Integer
moveToColdStorageAfterDays
          ]
      )