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

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

-- | The container element for specifying the default Object Lock retention
-- settings for new objects placed in the specified bucket.
--
-- -   The @DefaultRetention@ settings require both a mode and a period.
--
-- -   The @DefaultRetention@ period can be either @Days@ or @Years@ but
--     you must select one. You cannot specify @Days@ and @Years@ at the
--     same time.
--
-- /See:/ 'newDefaultRetention' smart constructor.
data DefaultRetention = DefaultRetention'
  { -- | The number of days that you want to specify for the default retention
    -- period. Must be used with @Mode@.
    DefaultRetention -> Maybe Int
days :: Prelude.Maybe Prelude.Int,
    -- | The default Object Lock retention mode you want to apply to new objects
    -- placed in the specified bucket. Must be used with either @Days@ or
    -- @Years@.
    DefaultRetention -> Maybe ObjectLockRetentionMode
mode :: Prelude.Maybe ObjectLockRetentionMode,
    -- | The number of years that you want to specify for the default retention
    -- period. Must be used with @Mode@.
    DefaultRetention -> Maybe Int
years :: Prelude.Maybe Prelude.Int
  }
  deriving (DefaultRetention -> DefaultRetention -> Bool
(DefaultRetention -> DefaultRetention -> Bool)
-> (DefaultRetention -> DefaultRetention -> Bool)
-> Eq DefaultRetention
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DefaultRetention -> DefaultRetention -> Bool
$c/= :: DefaultRetention -> DefaultRetention -> Bool
== :: DefaultRetention -> DefaultRetention -> Bool
$c== :: DefaultRetention -> DefaultRetention -> Bool
Prelude.Eq, ReadPrec [DefaultRetention]
ReadPrec DefaultRetention
Int -> ReadS DefaultRetention
ReadS [DefaultRetention]
(Int -> ReadS DefaultRetention)
-> ReadS [DefaultRetention]
-> ReadPrec DefaultRetention
-> ReadPrec [DefaultRetention]
-> Read DefaultRetention
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DefaultRetention]
$creadListPrec :: ReadPrec [DefaultRetention]
readPrec :: ReadPrec DefaultRetention
$creadPrec :: ReadPrec DefaultRetention
readList :: ReadS [DefaultRetention]
$creadList :: ReadS [DefaultRetention]
readsPrec :: Int -> ReadS DefaultRetention
$creadsPrec :: Int -> ReadS DefaultRetention
Prelude.Read, Int -> DefaultRetention -> ShowS
[DefaultRetention] -> ShowS
DefaultRetention -> String
(Int -> DefaultRetention -> ShowS)
-> (DefaultRetention -> String)
-> ([DefaultRetention] -> ShowS)
-> Show DefaultRetention
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DefaultRetention] -> ShowS
$cshowList :: [DefaultRetention] -> ShowS
show :: DefaultRetention -> String
$cshow :: DefaultRetention -> String
showsPrec :: Int -> DefaultRetention -> ShowS
$cshowsPrec :: Int -> DefaultRetention -> ShowS
Prelude.Show, (forall x. DefaultRetention -> Rep DefaultRetention x)
-> (forall x. Rep DefaultRetention x -> DefaultRetention)
-> Generic DefaultRetention
forall x. Rep DefaultRetention x -> DefaultRetention
forall x. DefaultRetention -> Rep DefaultRetention x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DefaultRetention x -> DefaultRetention
$cfrom :: forall x. DefaultRetention -> Rep DefaultRetention x
Prelude.Generic)

-- |
-- Create a value of 'DefaultRetention' 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', 'defaultRetention_days' - The number of days that you want to specify for the default retention
-- period. Must be used with @Mode@.
--
-- 'mode', 'defaultRetention_mode' - The default Object Lock retention mode you want to apply to new objects
-- placed in the specified bucket. Must be used with either @Days@ or
-- @Years@.
--
-- 'years', 'defaultRetention_years' - The number of years that you want to specify for the default retention
-- period. Must be used with @Mode@.
newDefaultRetention ::
  DefaultRetention
newDefaultRetention :: DefaultRetention
newDefaultRetention =
  DefaultRetention' :: Maybe Int
-> Maybe ObjectLockRetentionMode -> Maybe Int -> DefaultRetention
DefaultRetention'
    { $sel:days:DefaultRetention' :: Maybe Int
days = Maybe Int
forall a. Maybe a
Prelude.Nothing,
      $sel:mode:DefaultRetention' :: Maybe ObjectLockRetentionMode
mode = Maybe ObjectLockRetentionMode
forall a. Maybe a
Prelude.Nothing,
      $sel:years:DefaultRetention' :: Maybe Int
years = Maybe Int
forall a. Maybe a
Prelude.Nothing
    }

-- | The number of days that you want to specify for the default retention
-- period. Must be used with @Mode@.
defaultRetention_days :: Lens.Lens' DefaultRetention (Prelude.Maybe Prelude.Int)
defaultRetention_days :: (Maybe Int -> f (Maybe Int))
-> DefaultRetention -> f DefaultRetention
defaultRetention_days = (DefaultRetention -> Maybe Int)
-> (DefaultRetention -> Maybe Int -> DefaultRetention)
-> Lens DefaultRetention DefaultRetention (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DefaultRetention' {Maybe Int
days :: Maybe Int
$sel:days:DefaultRetention' :: DefaultRetention -> Maybe Int
days} -> Maybe Int
days) (\s :: DefaultRetention
s@DefaultRetention' {} Maybe Int
a -> DefaultRetention
s {$sel:days:DefaultRetention' :: Maybe Int
days = Maybe Int
a} :: DefaultRetention)

-- | The default Object Lock retention mode you want to apply to new objects
-- placed in the specified bucket. Must be used with either @Days@ or
-- @Years@.
defaultRetention_mode :: Lens.Lens' DefaultRetention (Prelude.Maybe ObjectLockRetentionMode)
defaultRetention_mode :: (Maybe ObjectLockRetentionMode
 -> f (Maybe ObjectLockRetentionMode))
-> DefaultRetention -> f DefaultRetention
defaultRetention_mode = (DefaultRetention -> Maybe ObjectLockRetentionMode)
-> (DefaultRetention
    -> Maybe ObjectLockRetentionMode -> DefaultRetention)
-> Lens
     DefaultRetention
     DefaultRetention
     (Maybe ObjectLockRetentionMode)
     (Maybe ObjectLockRetentionMode)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DefaultRetention' {Maybe ObjectLockRetentionMode
mode :: Maybe ObjectLockRetentionMode
$sel:mode:DefaultRetention' :: DefaultRetention -> Maybe ObjectLockRetentionMode
mode} -> Maybe ObjectLockRetentionMode
mode) (\s :: DefaultRetention
s@DefaultRetention' {} Maybe ObjectLockRetentionMode
a -> DefaultRetention
s {$sel:mode:DefaultRetention' :: Maybe ObjectLockRetentionMode
mode = Maybe ObjectLockRetentionMode
a} :: DefaultRetention)

-- | The number of years that you want to specify for the default retention
-- period. Must be used with @Mode@.
defaultRetention_years :: Lens.Lens' DefaultRetention (Prelude.Maybe Prelude.Int)
defaultRetention_years :: (Maybe Int -> f (Maybe Int))
-> DefaultRetention -> f DefaultRetention
defaultRetention_years = (DefaultRetention -> Maybe Int)
-> (DefaultRetention -> Maybe Int -> DefaultRetention)
-> Lens DefaultRetention DefaultRetention (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DefaultRetention' {Maybe Int
years :: Maybe Int
$sel:years:DefaultRetention' :: DefaultRetention -> Maybe Int
years} -> Maybe Int
years) (\s :: DefaultRetention
s@DefaultRetention' {} Maybe Int
a -> DefaultRetention
s {$sel:years:DefaultRetention' :: Maybe Int
years = Maybe Int
a} :: DefaultRetention)

instance Core.FromXML DefaultRetention where
  parseXML :: [Node] -> Either String DefaultRetention
parseXML [Node]
x =
    Maybe Int
-> Maybe ObjectLockRetentionMode -> Maybe Int -> DefaultRetention
DefaultRetention'
      (Maybe Int
 -> Maybe ObjectLockRetentionMode -> Maybe Int -> DefaultRetention)
-> Either String (Maybe Int)
-> Either
     String
     (Maybe ObjectLockRetentionMode -> Maybe Int -> DefaultRetention)
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 ObjectLockRetentionMode -> Maybe Int -> DefaultRetention)
-> Either String (Maybe ObjectLockRetentionMode)
-> Either String (Maybe Int -> DefaultRetention)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe ObjectLockRetentionMode)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Mode")
      Either String (Maybe Int -> DefaultRetention)
-> Either String (Maybe Int) -> Either String DefaultRetention
forall (f :: * -> *) a b. Applicative f => 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
"Years")

instance Prelude.Hashable DefaultRetention

instance Prelude.NFData DefaultRetention

instance Core.ToXML DefaultRetention where
  toXML :: DefaultRetention -> XML
toXML DefaultRetention' {Maybe Int
Maybe ObjectLockRetentionMode
years :: Maybe Int
mode :: Maybe ObjectLockRetentionMode
days :: Maybe Int
$sel:years:DefaultRetention' :: DefaultRetention -> Maybe Int
$sel:mode:DefaultRetention' :: DefaultRetention -> Maybe ObjectLockRetentionMode
$sel:days:DefaultRetention' :: DefaultRetention -> 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
"Mode" Name -> Maybe ObjectLockRetentionMode -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe ObjectLockRetentionMode
mode,
        Name
"Years" Name -> Maybe Int -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe Int
years
      ]