{-# 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.EFS.Types.LifecyclePolicy
-- 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.EFS.Types.LifecyclePolicy where

import qualified Amazonka.Core as Core
import Amazonka.EFS.Types.TransitionToIARules
import Amazonka.EFS.Types.TransitionToPrimaryStorageClassRules
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Describes a policy used by EFS lifecycle management and EFS intelligent
-- tiering that specifies when to transition files into and out of the file
-- system\'s Infrequent Access (IA) storage class. For more information,
-- see
-- <https://docs.aws.amazon.com/efs/latest/ug/lifecycle-management-efs.html EFS Intelligent‐Tiering and EFS Lifecycle Management>.
--
-- When using the @put-lifecycle-configuration@ CLI command or the
-- @PutLifecycleConfiguration@ API action, Amazon EFS requires that each
-- @LifecyclePolicy@ object have only a single transition. This means that
-- in a request body, @LifecyclePolicies@ needs to be structured as an
-- array of @LifecyclePolicy@ objects, one object for each transition,
-- @TransitionToIA@, @TransitionToPrimaryStorageClass@. For more
-- information, see the request examples in PutLifecycleConfiguration.
--
-- /See:/ 'newLifecyclePolicy' smart constructor.
data LifecyclePolicy = LifecyclePolicy'
  { -- | Describes the period of time that a file is not accessed, after which it
    -- transitions to IA storage. Metadata operations such as listing the
    -- contents of a directory don\'t count as file access events.
    LifecyclePolicy -> Maybe TransitionToIARules
transitionToIA :: Prelude.Maybe TransitionToIARules,
    -- | Describes when to transition a file from IA storage to primary storage.
    -- Metadata operations such as listing the contents of a directory don\'t
    -- count as file access events.
    LifecyclePolicy -> Maybe TransitionToPrimaryStorageClassRules
transitionToPrimaryStorageClass :: Prelude.Maybe TransitionToPrimaryStorageClassRules
  }
  deriving (LifecyclePolicy -> LifecyclePolicy -> Bool
(LifecyclePolicy -> LifecyclePolicy -> Bool)
-> (LifecyclePolicy -> LifecyclePolicy -> Bool)
-> Eq LifecyclePolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LifecyclePolicy -> LifecyclePolicy -> Bool
$c/= :: LifecyclePolicy -> LifecyclePolicy -> Bool
== :: LifecyclePolicy -> LifecyclePolicy -> Bool
$c== :: LifecyclePolicy -> LifecyclePolicy -> Bool
Prelude.Eq, ReadPrec [LifecyclePolicy]
ReadPrec LifecyclePolicy
Int -> ReadS LifecyclePolicy
ReadS [LifecyclePolicy]
(Int -> ReadS LifecyclePolicy)
-> ReadS [LifecyclePolicy]
-> ReadPrec LifecyclePolicy
-> ReadPrec [LifecyclePolicy]
-> Read LifecyclePolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [LifecyclePolicy]
$creadListPrec :: ReadPrec [LifecyclePolicy]
readPrec :: ReadPrec LifecyclePolicy
$creadPrec :: ReadPrec LifecyclePolicy
readList :: ReadS [LifecyclePolicy]
$creadList :: ReadS [LifecyclePolicy]
readsPrec :: Int -> ReadS LifecyclePolicy
$creadsPrec :: Int -> ReadS LifecyclePolicy
Prelude.Read, Int -> LifecyclePolicy -> ShowS
[LifecyclePolicy] -> ShowS
LifecyclePolicy -> String
(Int -> LifecyclePolicy -> ShowS)
-> (LifecyclePolicy -> String)
-> ([LifecyclePolicy] -> ShowS)
-> Show LifecyclePolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LifecyclePolicy] -> ShowS
$cshowList :: [LifecyclePolicy] -> ShowS
show :: LifecyclePolicy -> String
$cshow :: LifecyclePolicy -> String
showsPrec :: Int -> LifecyclePolicy -> ShowS
$cshowsPrec :: Int -> LifecyclePolicy -> ShowS
Prelude.Show, (forall x. LifecyclePolicy -> Rep LifecyclePolicy x)
-> (forall x. Rep LifecyclePolicy x -> LifecyclePolicy)
-> Generic LifecyclePolicy
forall x. Rep LifecyclePolicy x -> LifecyclePolicy
forall x. LifecyclePolicy -> Rep LifecyclePolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LifecyclePolicy x -> LifecyclePolicy
$cfrom :: forall x. LifecyclePolicy -> Rep LifecyclePolicy x
Prelude.Generic)

-- |
-- Create a value of 'LifecyclePolicy' 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:
--
-- 'transitionToIA', 'lifecyclePolicy_transitionToIA' - Describes the period of time that a file is not accessed, after which it
-- transitions to IA storage. Metadata operations such as listing the
-- contents of a directory don\'t count as file access events.
--
-- 'transitionToPrimaryStorageClass', 'lifecyclePolicy_transitionToPrimaryStorageClass' - Describes when to transition a file from IA storage to primary storage.
-- Metadata operations such as listing the contents of a directory don\'t
-- count as file access events.
newLifecyclePolicy ::
  LifecyclePolicy
newLifecyclePolicy :: LifecyclePolicy
newLifecyclePolicy =
  LifecyclePolicy' :: Maybe TransitionToIARules
-> Maybe TransitionToPrimaryStorageClassRules -> LifecyclePolicy
LifecyclePolicy'
    { $sel:transitionToIA:LifecyclePolicy' :: Maybe TransitionToIARules
transitionToIA = Maybe TransitionToIARules
forall a. Maybe a
Prelude.Nothing,
      $sel:transitionToPrimaryStorageClass:LifecyclePolicy' :: Maybe TransitionToPrimaryStorageClassRules
transitionToPrimaryStorageClass = Maybe TransitionToPrimaryStorageClassRules
forall a. Maybe a
Prelude.Nothing
    }

-- | Describes the period of time that a file is not accessed, after which it
-- transitions to IA storage. Metadata operations such as listing the
-- contents of a directory don\'t count as file access events.
lifecyclePolicy_transitionToIA :: Lens.Lens' LifecyclePolicy (Prelude.Maybe TransitionToIARules)
lifecyclePolicy_transitionToIA :: (Maybe TransitionToIARules -> f (Maybe TransitionToIARules))
-> LifecyclePolicy -> f LifecyclePolicy
lifecyclePolicy_transitionToIA = (LifecyclePolicy -> Maybe TransitionToIARules)
-> (LifecyclePolicy
    -> Maybe TransitionToIARules -> LifecyclePolicy)
-> Lens
     LifecyclePolicy
     LifecyclePolicy
     (Maybe TransitionToIARules)
     (Maybe TransitionToIARules)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LifecyclePolicy' {Maybe TransitionToIARules
transitionToIA :: Maybe TransitionToIARules
$sel:transitionToIA:LifecyclePolicy' :: LifecyclePolicy -> Maybe TransitionToIARules
transitionToIA} -> Maybe TransitionToIARules
transitionToIA) (\s :: LifecyclePolicy
s@LifecyclePolicy' {} Maybe TransitionToIARules
a -> LifecyclePolicy
s {$sel:transitionToIA:LifecyclePolicy' :: Maybe TransitionToIARules
transitionToIA = Maybe TransitionToIARules
a} :: LifecyclePolicy)

-- | Describes when to transition a file from IA storage to primary storage.
-- Metadata operations such as listing the contents of a directory don\'t
-- count as file access events.
lifecyclePolicy_transitionToPrimaryStorageClass :: Lens.Lens' LifecyclePolicy (Prelude.Maybe TransitionToPrimaryStorageClassRules)
lifecyclePolicy_transitionToPrimaryStorageClass :: (Maybe TransitionToPrimaryStorageClassRules
 -> f (Maybe TransitionToPrimaryStorageClassRules))
-> LifecyclePolicy -> f LifecyclePolicy
lifecyclePolicy_transitionToPrimaryStorageClass = (LifecyclePolicy -> Maybe TransitionToPrimaryStorageClassRules)
-> (LifecyclePolicy
    -> Maybe TransitionToPrimaryStorageClassRules -> LifecyclePolicy)
-> Lens
     LifecyclePolicy
     LifecyclePolicy
     (Maybe TransitionToPrimaryStorageClassRules)
     (Maybe TransitionToPrimaryStorageClassRules)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LifecyclePolicy' {Maybe TransitionToPrimaryStorageClassRules
transitionToPrimaryStorageClass :: Maybe TransitionToPrimaryStorageClassRules
$sel:transitionToPrimaryStorageClass:LifecyclePolicy' :: LifecyclePolicy -> Maybe TransitionToPrimaryStorageClassRules
transitionToPrimaryStorageClass} -> Maybe TransitionToPrimaryStorageClassRules
transitionToPrimaryStorageClass) (\s :: LifecyclePolicy
s@LifecyclePolicy' {} Maybe TransitionToPrimaryStorageClassRules
a -> LifecyclePolicy
s {$sel:transitionToPrimaryStorageClass:LifecyclePolicy' :: Maybe TransitionToPrimaryStorageClassRules
transitionToPrimaryStorageClass = Maybe TransitionToPrimaryStorageClassRules
a} :: LifecyclePolicy)

instance Core.FromJSON LifecyclePolicy where
  parseJSON :: Value -> Parser LifecyclePolicy
parseJSON =
    String
-> (Object -> Parser LifecyclePolicy)
-> Value
-> Parser LifecyclePolicy
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"LifecyclePolicy"
      ( \Object
x ->
          Maybe TransitionToIARules
-> Maybe TransitionToPrimaryStorageClassRules -> LifecyclePolicy
LifecyclePolicy'
            (Maybe TransitionToIARules
 -> Maybe TransitionToPrimaryStorageClassRules -> LifecyclePolicy)
-> Parser (Maybe TransitionToIARules)
-> Parser
     (Maybe TransitionToPrimaryStorageClassRules -> LifecyclePolicy)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe TransitionToIARules)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"TransitionToIA")
            Parser
  (Maybe TransitionToPrimaryStorageClassRules -> LifecyclePolicy)
-> Parser (Maybe TransitionToPrimaryStorageClassRules)
-> Parser LifecyclePolicy
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object
-> Text -> Parser (Maybe TransitionToPrimaryStorageClassRules)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"TransitionToPrimaryStorageClass")
      )

instance Prelude.Hashable LifecyclePolicy

instance Prelude.NFData LifecyclePolicy

instance Core.ToJSON LifecyclePolicy where
  toJSON :: LifecyclePolicy -> Value
toJSON LifecyclePolicy' {Maybe TransitionToIARules
Maybe TransitionToPrimaryStorageClassRules
transitionToPrimaryStorageClass :: Maybe TransitionToPrimaryStorageClassRules
transitionToIA :: Maybe TransitionToIARules
$sel:transitionToPrimaryStorageClass:LifecyclePolicy' :: LifecyclePolicy -> Maybe TransitionToPrimaryStorageClassRules
$sel:transitionToIA:LifecyclePolicy' :: LifecyclePolicy -> Maybe TransitionToIARules
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"TransitionToIA" Text -> TransitionToIARules -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (TransitionToIARules -> Pair)
-> Maybe TransitionToIARules -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe TransitionToIARules
transitionToIA,
            (Text
"TransitionToPrimaryStorageClass" Text -> TransitionToPrimaryStorageClassRules -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (TransitionToPrimaryStorageClassRules -> Pair)
-> Maybe TransitionToPrimaryStorageClassRules -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe TransitionToPrimaryStorageClassRules
transitionToPrimaryStorageClass
          ]
      )