{-# 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.S3.Types.LifecycleExpiration
-- 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.S3.Types.LifecycleExpiration where

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

-- | Container for the expiration for the lifecycle of the object.
--
-- /See:/ 'newLifecycleExpiration' smart constructor.
data LifecycleExpiration = LifecycleExpiration'
  { -- | Indicates the lifetime, in days, of the objects that are subject to the
    -- rule. The value must be a non-zero positive integer.
    LifecycleExpiration -> Maybe Int
days :: Prelude.Maybe Prelude.Int,
    -- | Indicates at what date the object is to be moved or deleted. Should be
    -- in GMT ISO 8601 Format.
    LifecycleExpiration -> Maybe ISO8601
date :: Prelude.Maybe Core.ISO8601,
    -- | Indicates whether Amazon S3 will remove a delete marker with no
    -- noncurrent versions. If set to true, the delete marker will be expired;
    -- if set to false the policy takes no action. This cannot be specified
    -- with Days or Date in a Lifecycle Expiration Policy.
    LifecycleExpiration -> Maybe Bool
expiredObjectDeleteMarker :: Prelude.Maybe Prelude.Bool
  }
  deriving (LifecycleExpiration -> LifecycleExpiration -> Bool
(LifecycleExpiration -> LifecycleExpiration -> Bool)
-> (LifecycleExpiration -> LifecycleExpiration -> Bool)
-> Eq LifecycleExpiration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LifecycleExpiration -> LifecycleExpiration -> Bool
$c/= :: LifecycleExpiration -> LifecycleExpiration -> Bool
== :: LifecycleExpiration -> LifecycleExpiration -> Bool
$c== :: LifecycleExpiration -> LifecycleExpiration -> Bool
Prelude.Eq, ReadPrec [LifecycleExpiration]
ReadPrec LifecycleExpiration
Int -> ReadS LifecycleExpiration
ReadS [LifecycleExpiration]
(Int -> ReadS LifecycleExpiration)
-> ReadS [LifecycleExpiration]
-> ReadPrec LifecycleExpiration
-> ReadPrec [LifecycleExpiration]
-> Read LifecycleExpiration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [LifecycleExpiration]
$creadListPrec :: ReadPrec [LifecycleExpiration]
readPrec :: ReadPrec LifecycleExpiration
$creadPrec :: ReadPrec LifecycleExpiration
readList :: ReadS [LifecycleExpiration]
$creadList :: ReadS [LifecycleExpiration]
readsPrec :: Int -> ReadS LifecycleExpiration
$creadsPrec :: Int -> ReadS LifecycleExpiration
Prelude.Read, Int -> LifecycleExpiration -> ShowS
[LifecycleExpiration] -> ShowS
LifecycleExpiration -> String
(Int -> LifecycleExpiration -> ShowS)
-> (LifecycleExpiration -> String)
-> ([LifecycleExpiration] -> ShowS)
-> Show LifecycleExpiration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LifecycleExpiration] -> ShowS
$cshowList :: [LifecycleExpiration] -> ShowS
show :: LifecycleExpiration -> String
$cshow :: LifecycleExpiration -> String
showsPrec :: Int -> LifecycleExpiration -> ShowS
$cshowsPrec :: Int -> LifecycleExpiration -> ShowS
Prelude.Show, (forall x. LifecycleExpiration -> Rep LifecycleExpiration x)
-> (forall x. Rep LifecycleExpiration x -> LifecycleExpiration)
-> Generic LifecycleExpiration
forall x. Rep LifecycleExpiration x -> LifecycleExpiration
forall x. LifecycleExpiration -> Rep LifecycleExpiration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LifecycleExpiration x -> LifecycleExpiration
$cfrom :: forall x. LifecycleExpiration -> Rep LifecycleExpiration x
Prelude.Generic)

-- |
-- Create a value of 'LifecycleExpiration' 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:
--
-- 'days', 'lifecycleExpiration_days' - Indicates the lifetime, in days, of the objects that are subject to the
-- rule. The value must be a non-zero positive integer.
--
-- 'date', 'lifecycleExpiration_date' - Indicates at what date the object is to be moved or deleted. Should be
-- in GMT ISO 8601 Format.
--
-- 'expiredObjectDeleteMarker', 'lifecycleExpiration_expiredObjectDeleteMarker' - Indicates whether Amazon S3 will remove a delete marker with no
-- noncurrent versions. If set to true, the delete marker will be expired;
-- if set to false the policy takes no action. This cannot be specified
-- with Days or Date in a Lifecycle Expiration Policy.
newLifecycleExpiration ::
  LifecycleExpiration
newLifecycleExpiration :: LifecycleExpiration
newLifecycleExpiration =
  LifecycleExpiration' :: Maybe Int -> Maybe ISO8601 -> Maybe Bool -> LifecycleExpiration
LifecycleExpiration'
    { $sel:days:LifecycleExpiration' :: Maybe Int
days = Maybe Int
forall a. Maybe a
Prelude.Nothing,
      $sel:date:LifecycleExpiration' :: Maybe ISO8601
date = Maybe ISO8601
forall a. Maybe a
Prelude.Nothing,
      $sel:expiredObjectDeleteMarker:LifecycleExpiration' :: Maybe Bool
expiredObjectDeleteMarker = Maybe Bool
forall a. Maybe a
Prelude.Nothing
    }

-- | Indicates the lifetime, in days, of the objects that are subject to the
-- rule. The value must be a non-zero positive integer.
lifecycleExpiration_days :: Lens.Lens' LifecycleExpiration (Prelude.Maybe Prelude.Int)
lifecycleExpiration_days :: (Maybe Int -> f (Maybe Int))
-> LifecycleExpiration -> f LifecycleExpiration
lifecycleExpiration_days = (LifecycleExpiration -> Maybe Int)
-> (LifecycleExpiration -> Maybe Int -> LifecycleExpiration)
-> Lens
     LifecycleExpiration LifecycleExpiration (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LifecycleExpiration' {Maybe Int
days :: Maybe Int
$sel:days:LifecycleExpiration' :: LifecycleExpiration -> Maybe Int
days} -> Maybe Int
days) (\s :: LifecycleExpiration
s@LifecycleExpiration' {} Maybe Int
a -> LifecycleExpiration
s {$sel:days:LifecycleExpiration' :: Maybe Int
days = Maybe Int
a} :: LifecycleExpiration)

-- | Indicates at what date the object is to be moved or deleted. Should be
-- in GMT ISO 8601 Format.
lifecycleExpiration_date :: Lens.Lens' LifecycleExpiration (Prelude.Maybe Prelude.UTCTime)
lifecycleExpiration_date :: (Maybe UTCTime -> f (Maybe UTCTime))
-> LifecycleExpiration -> f LifecycleExpiration
lifecycleExpiration_date = (LifecycleExpiration -> Maybe ISO8601)
-> (LifecycleExpiration -> Maybe ISO8601 -> LifecycleExpiration)
-> Lens
     LifecycleExpiration
     LifecycleExpiration
     (Maybe ISO8601)
     (Maybe ISO8601)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LifecycleExpiration' {Maybe ISO8601
date :: Maybe ISO8601
$sel:date:LifecycleExpiration' :: LifecycleExpiration -> Maybe ISO8601
date} -> Maybe ISO8601
date) (\s :: LifecycleExpiration
s@LifecycleExpiration' {} Maybe ISO8601
a -> LifecycleExpiration
s {$sel:date:LifecycleExpiration' :: Maybe ISO8601
date = Maybe ISO8601
a} :: LifecycleExpiration) ((Maybe ISO8601 -> f (Maybe ISO8601))
 -> LifecycleExpiration -> f LifecycleExpiration)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe ISO8601 -> f (Maybe ISO8601))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> LifecycleExpiration
-> f LifecycleExpiration
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso ISO8601 ISO8601 UTCTime UTCTime
-> Iso
     (Maybe ISO8601) (Maybe ISO8601) (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 ISO8601 ISO8601 UTCTime UTCTime
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

-- | Indicates whether Amazon S3 will remove a delete marker with no
-- noncurrent versions. If set to true, the delete marker will be expired;
-- if set to false the policy takes no action. This cannot be specified
-- with Days or Date in a Lifecycle Expiration Policy.
lifecycleExpiration_expiredObjectDeleteMarker :: Lens.Lens' LifecycleExpiration (Prelude.Maybe Prelude.Bool)
lifecycleExpiration_expiredObjectDeleteMarker :: (Maybe Bool -> f (Maybe Bool))
-> LifecycleExpiration -> f LifecycleExpiration
lifecycleExpiration_expiredObjectDeleteMarker = (LifecycleExpiration -> Maybe Bool)
-> (LifecycleExpiration -> Maybe Bool -> LifecycleExpiration)
-> Lens
     LifecycleExpiration LifecycleExpiration (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LifecycleExpiration' {Maybe Bool
expiredObjectDeleteMarker :: Maybe Bool
$sel:expiredObjectDeleteMarker:LifecycleExpiration' :: LifecycleExpiration -> Maybe Bool
expiredObjectDeleteMarker} -> Maybe Bool
expiredObjectDeleteMarker) (\s :: LifecycleExpiration
s@LifecycleExpiration' {} Maybe Bool
a -> LifecycleExpiration
s {$sel:expiredObjectDeleteMarker:LifecycleExpiration' :: Maybe Bool
expiredObjectDeleteMarker = Maybe Bool
a} :: LifecycleExpiration)

instance Core.FromXML LifecycleExpiration where
  parseXML :: [Node] -> Either String LifecycleExpiration
parseXML [Node]
x =
    Maybe Int -> Maybe ISO8601 -> Maybe Bool -> LifecycleExpiration
LifecycleExpiration'
      (Maybe Int -> Maybe ISO8601 -> Maybe Bool -> LifecycleExpiration)
-> Either String (Maybe Int)
-> Either
     String (Maybe ISO8601 -> Maybe Bool -> LifecycleExpiration)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe Int)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Days")
      Either String (Maybe ISO8601 -> Maybe Bool -> LifecycleExpiration)
-> Either String (Maybe ISO8601)
-> Either String (Maybe Bool -> LifecycleExpiration)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe ISO8601)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Date")
      Either String (Maybe Bool -> LifecycleExpiration)
-> Either String (Maybe Bool) -> Either String LifecycleExpiration
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Bool)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"ExpiredObjectDeleteMarker")

instance Prelude.Hashable LifecycleExpiration

instance Prelude.NFData LifecycleExpiration

instance Core.ToXML LifecycleExpiration where
  toXML :: LifecycleExpiration -> XML
toXML LifecycleExpiration' {Maybe Bool
Maybe Int
Maybe ISO8601
expiredObjectDeleteMarker :: Maybe Bool
date :: Maybe ISO8601
days :: Maybe Int
$sel:expiredObjectDeleteMarker:LifecycleExpiration' :: LifecycleExpiration -> Maybe Bool
$sel:date:LifecycleExpiration' :: LifecycleExpiration -> Maybe ISO8601
$sel:days:LifecycleExpiration' :: LifecycleExpiration -> Maybe Int
..} =
    [XML] -> XML
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"Days" Name -> Maybe Int -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe Int
days,
        Name
"Date" Name -> Maybe ISO8601 -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe ISO8601
date,
        Name
"ExpiredObjectDeleteMarker"
          Name -> Maybe Bool -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe Bool
expiredObjectDeleteMarker
      ]