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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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 “expire after days”
-- 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.
--
-- Only Amazon EFS file system backups can be transitioned to cold storage.
--
-- /See:/ 'newLifecycle' smart constructor.
data Lifecycle = Lifecycle'
  { -- | Specifies the number of days after creation that a recovery point is
    -- moved to cold storage.
    Lifecycle -> Maybe Integer
moveToColdStorageAfterDays :: Prelude.Maybe Prelude.Integer,
    -- | 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
  }
  deriving (Lifecycle -> Lifecycle -> Bool
(Lifecycle -> Lifecycle -> Bool)
-> (Lifecycle -> Lifecycle -> Bool) -> Eq Lifecycle
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]
(Int -> ReadS Lifecycle)
-> ReadS [Lifecycle]
-> ReadPrec Lifecycle
-> ReadPrec [Lifecycle]
-> Read 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
(Int -> Lifecycle -> ShowS)
-> (Lifecycle -> String)
-> ([Lifecycle] -> ShowS)
-> Show Lifecycle
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. Lifecycle -> Rep Lifecycle x)
-> (forall x. Rep Lifecycle x -> Lifecycle) -> Generic Lifecycle
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:
--
-- 'moveToColdStorageAfterDays', 'lifecycle_moveToColdStorageAfterDays' - Specifies the number of days after creation that a recovery point is
-- moved to cold storage.
--
-- 'deleteAfterDays', 'lifecycle_deleteAfterDays' - Specifies the number of days after creation that a recovery point is
-- deleted. Must be greater than 90 days plus @MoveToColdStorageAfterDays@.
newLifecycle ::
  Lifecycle
newLifecycle :: Lifecycle
newLifecycle =
  Lifecycle' :: Maybe Integer -> Maybe Integer -> Lifecycle
Lifecycle'
    { $sel:moveToColdStorageAfterDays:Lifecycle' :: Maybe Integer
moveToColdStorageAfterDays =
        Maybe Integer
forall a. Maybe a
Prelude.Nothing,
      $sel:deleteAfterDays:Lifecycle' :: Maybe Integer
deleteAfterDays = Maybe Integer
forall a. Maybe a
Prelude.Nothing
    }

-- | 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 :: (Maybe Integer -> f (Maybe Integer)) -> Lifecycle -> f Lifecycle
lifecycle_moveToColdStorageAfterDays = (Lifecycle -> Maybe Integer)
-> (Lifecycle -> Maybe Integer -> Lifecycle)
-> Lens Lifecycle Lifecycle (Maybe Integer) (Maybe Integer)
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)

-- | 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 :: (Maybe Integer -> f (Maybe Integer)) -> Lifecycle -> f Lifecycle
lifecycle_deleteAfterDays = (Lifecycle -> Maybe Integer)
-> (Lifecycle -> Maybe Integer -> Lifecycle)
-> Lens Lifecycle Lifecycle (Maybe Integer) (Maybe Integer)
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)

instance Core.FromJSON Lifecycle where
  parseJSON :: Value -> Parser Lifecycle
parseJSON =
    String -> (Object -> Parser Lifecycle) -> Value -> Parser Lifecycle
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Lifecycle"
      ( \Object
x ->
          Maybe Integer -> Maybe Integer -> Lifecycle
Lifecycle'
            (Maybe Integer -> Maybe Integer -> Lifecycle)
-> Parser (Maybe Integer) -> Parser (Maybe Integer -> Lifecycle)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Integer)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"MoveToColdStorageAfterDays")
            Parser (Maybe Integer -> Lifecycle)
-> Parser (Maybe Integer) -> Parser Lifecycle
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Integer)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"DeleteAfterDays")
      )

instance Prelude.Hashable Lifecycle

instance Prelude.NFData Lifecycle

instance Core.ToJSON Lifecycle where
  toJSON :: Lifecycle -> Value
toJSON Lifecycle' {Maybe Integer
deleteAfterDays :: Maybe Integer
moveToColdStorageAfterDays :: Maybe Integer
$sel:deleteAfterDays:Lifecycle' :: Lifecycle -> Maybe Integer
$sel:moveToColdStorageAfterDays:Lifecycle' :: Lifecycle -> Maybe Integer
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"MoveToColdStorageAfterDays" Text -> Integer -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Integer -> Pair) -> Maybe Integer -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Integer
moveToColdStorageAfterDays,
            (Text
"DeleteAfterDays" Text -> Integer -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Integer -> Pair) -> Maybe Integer -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Integer
deleteAfterDays
          ]
      )