{-# 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.CalculatedLifecycle
-- 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.CalculatedLifecycle where

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

-- | Contains @DeleteAt@ and @MoveToColdStorageAt@ timestamps, which are used
-- to specify a lifecycle for a recovery point.
--
-- The lifecycle defines when a protected resource is transitioned to cold
-- storage and when it expires. Backup transitions and expires backups
-- automatically according to the lifecycle that you define.
--
-- Backups transitioned to cold storage must be stored in cold storage for
-- a minimum of 90 days. Therefore, 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:/ 'newCalculatedLifecycle' smart constructor.
data CalculatedLifecycle = CalculatedLifecycle'
  { -- | A timestamp that specifies when to delete a recovery point.
    CalculatedLifecycle -> Maybe POSIX
deleteAt :: Prelude.Maybe Core.POSIX,
    -- | A timestamp that specifies when to transition a recovery point to cold
    -- storage.
    CalculatedLifecycle -> Maybe POSIX
moveToColdStorageAt :: Prelude.Maybe Core.POSIX
  }
  deriving (CalculatedLifecycle -> CalculatedLifecycle -> Bool
(CalculatedLifecycle -> CalculatedLifecycle -> Bool)
-> (CalculatedLifecycle -> CalculatedLifecycle -> Bool)
-> Eq CalculatedLifecycle
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CalculatedLifecycle -> CalculatedLifecycle -> Bool
$c/= :: CalculatedLifecycle -> CalculatedLifecycle -> Bool
== :: CalculatedLifecycle -> CalculatedLifecycle -> Bool
$c== :: CalculatedLifecycle -> CalculatedLifecycle -> Bool
Prelude.Eq, ReadPrec [CalculatedLifecycle]
ReadPrec CalculatedLifecycle
Int -> ReadS CalculatedLifecycle
ReadS [CalculatedLifecycle]
(Int -> ReadS CalculatedLifecycle)
-> ReadS [CalculatedLifecycle]
-> ReadPrec CalculatedLifecycle
-> ReadPrec [CalculatedLifecycle]
-> Read CalculatedLifecycle
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CalculatedLifecycle]
$creadListPrec :: ReadPrec [CalculatedLifecycle]
readPrec :: ReadPrec CalculatedLifecycle
$creadPrec :: ReadPrec CalculatedLifecycle
readList :: ReadS [CalculatedLifecycle]
$creadList :: ReadS [CalculatedLifecycle]
readsPrec :: Int -> ReadS CalculatedLifecycle
$creadsPrec :: Int -> ReadS CalculatedLifecycle
Prelude.Read, Int -> CalculatedLifecycle -> ShowS
[CalculatedLifecycle] -> ShowS
CalculatedLifecycle -> String
(Int -> CalculatedLifecycle -> ShowS)
-> (CalculatedLifecycle -> String)
-> ([CalculatedLifecycle] -> ShowS)
-> Show CalculatedLifecycle
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CalculatedLifecycle] -> ShowS
$cshowList :: [CalculatedLifecycle] -> ShowS
show :: CalculatedLifecycle -> String
$cshow :: CalculatedLifecycle -> String
showsPrec :: Int -> CalculatedLifecycle -> ShowS
$cshowsPrec :: Int -> CalculatedLifecycle -> ShowS
Prelude.Show, (forall x. CalculatedLifecycle -> Rep CalculatedLifecycle x)
-> (forall x. Rep CalculatedLifecycle x -> CalculatedLifecycle)
-> Generic CalculatedLifecycle
forall x. Rep CalculatedLifecycle x -> CalculatedLifecycle
forall x. CalculatedLifecycle -> Rep CalculatedLifecycle x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CalculatedLifecycle x -> CalculatedLifecycle
$cfrom :: forall x. CalculatedLifecycle -> Rep CalculatedLifecycle x
Prelude.Generic)

-- |
-- Create a value of 'CalculatedLifecycle' 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:
--
-- 'deleteAt', 'calculatedLifecycle_deleteAt' - A timestamp that specifies when to delete a recovery point.
--
-- 'moveToColdStorageAt', 'calculatedLifecycle_moveToColdStorageAt' - A timestamp that specifies when to transition a recovery point to cold
-- storage.
newCalculatedLifecycle ::
  CalculatedLifecycle
newCalculatedLifecycle :: CalculatedLifecycle
newCalculatedLifecycle =
  CalculatedLifecycle' :: Maybe POSIX -> Maybe POSIX -> CalculatedLifecycle
CalculatedLifecycle'
    { $sel:deleteAt:CalculatedLifecycle' :: Maybe POSIX
deleteAt = Maybe POSIX
forall a. Maybe a
Prelude.Nothing,
      $sel:moveToColdStorageAt:CalculatedLifecycle' :: Maybe POSIX
moveToColdStorageAt = Maybe POSIX
forall a. Maybe a
Prelude.Nothing
    }

-- | A timestamp that specifies when to delete a recovery point.
calculatedLifecycle_deleteAt :: Lens.Lens' CalculatedLifecycle (Prelude.Maybe Prelude.UTCTime)
calculatedLifecycle_deleteAt :: (Maybe UTCTime -> f (Maybe UTCTime))
-> CalculatedLifecycle -> f CalculatedLifecycle
calculatedLifecycle_deleteAt = (CalculatedLifecycle -> Maybe POSIX)
-> (CalculatedLifecycle -> Maybe POSIX -> CalculatedLifecycle)
-> Lens
     CalculatedLifecycle CalculatedLifecycle (Maybe POSIX) (Maybe POSIX)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CalculatedLifecycle' {Maybe POSIX
deleteAt :: Maybe POSIX
$sel:deleteAt:CalculatedLifecycle' :: CalculatedLifecycle -> Maybe POSIX
deleteAt} -> Maybe POSIX
deleteAt) (\s :: CalculatedLifecycle
s@CalculatedLifecycle' {} Maybe POSIX
a -> CalculatedLifecycle
s {$sel:deleteAt:CalculatedLifecycle' :: Maybe POSIX
deleteAt = Maybe POSIX
a} :: CalculatedLifecycle) ((Maybe POSIX -> f (Maybe POSIX))
 -> CalculatedLifecycle -> f CalculatedLifecycle)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> CalculatedLifecycle
-> f CalculatedLifecycle
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso POSIX POSIX UTCTime UTCTime
-> Iso (Maybe POSIX) (Maybe POSIX) (Maybe UTCTime) (Maybe UTCTime)
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso POSIX POSIX UTCTime UTCTime
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

-- | A timestamp that specifies when to transition a recovery point to cold
-- storage.
calculatedLifecycle_moveToColdStorageAt :: Lens.Lens' CalculatedLifecycle (Prelude.Maybe Prelude.UTCTime)
calculatedLifecycle_moveToColdStorageAt :: (Maybe UTCTime -> f (Maybe UTCTime))
-> CalculatedLifecycle -> f CalculatedLifecycle
calculatedLifecycle_moveToColdStorageAt = (CalculatedLifecycle -> Maybe POSIX)
-> (CalculatedLifecycle -> Maybe POSIX -> CalculatedLifecycle)
-> Lens
     CalculatedLifecycle CalculatedLifecycle (Maybe POSIX) (Maybe POSIX)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CalculatedLifecycle' {Maybe POSIX
moveToColdStorageAt :: Maybe POSIX
$sel:moveToColdStorageAt:CalculatedLifecycle' :: CalculatedLifecycle -> Maybe POSIX
moveToColdStorageAt} -> Maybe POSIX
moveToColdStorageAt) (\s :: CalculatedLifecycle
s@CalculatedLifecycle' {} Maybe POSIX
a -> CalculatedLifecycle
s {$sel:moveToColdStorageAt:CalculatedLifecycle' :: Maybe POSIX
moveToColdStorageAt = Maybe POSIX
a} :: CalculatedLifecycle) ((Maybe POSIX -> f (Maybe POSIX))
 -> CalculatedLifecycle -> f CalculatedLifecycle)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> CalculatedLifecycle
-> f CalculatedLifecycle
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso POSIX POSIX UTCTime UTCTime
-> Iso (Maybe POSIX) (Maybe POSIX) (Maybe UTCTime) (Maybe UTCTime)
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso POSIX POSIX UTCTime UTCTime
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

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

instance Prelude.Hashable CalculatedLifecycle

instance Prelude.NFData CalculatedLifecycle