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

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

-- |
-- Create a value of 'ObjectLockRule' 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:
--
-- 'defaultRetention', 'objectLockRule_defaultRetention' - The default Object Lock retention mode and period that you want to apply
-- to new objects placed in the specified bucket. Bucket settings require
-- both a mode and a period. The period can be either @Days@ or @Years@ but
-- you must select one. You cannot specify @Days@ and @Years@ at the same
-- time.
newObjectLockRule ::
  ObjectLockRule
newObjectLockRule :: ObjectLockRule
newObjectLockRule =
  ObjectLockRule' :: Maybe DefaultRetention -> ObjectLockRule
ObjectLockRule' {$sel:defaultRetention:ObjectLockRule' :: Maybe DefaultRetention
defaultRetention = Maybe DefaultRetention
forall a. Maybe a
Prelude.Nothing}

-- | The default Object Lock retention mode and period that you want to apply
-- to new objects placed in the specified bucket. Bucket settings require
-- both a mode and a period. The period can be either @Days@ or @Years@ but
-- you must select one. You cannot specify @Days@ and @Years@ at the same
-- time.
objectLockRule_defaultRetention :: Lens.Lens' ObjectLockRule (Prelude.Maybe DefaultRetention)
objectLockRule_defaultRetention :: (Maybe DefaultRetention -> f (Maybe DefaultRetention))
-> ObjectLockRule -> f ObjectLockRule
objectLockRule_defaultRetention = (ObjectLockRule -> Maybe DefaultRetention)
-> (ObjectLockRule -> Maybe DefaultRetention -> ObjectLockRule)
-> Lens
     ObjectLockRule
     ObjectLockRule
     (Maybe DefaultRetention)
     (Maybe DefaultRetention)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ObjectLockRule' {Maybe DefaultRetention
defaultRetention :: Maybe DefaultRetention
$sel:defaultRetention:ObjectLockRule' :: ObjectLockRule -> Maybe DefaultRetention
defaultRetention} -> Maybe DefaultRetention
defaultRetention) (\s :: ObjectLockRule
s@ObjectLockRule' {} Maybe DefaultRetention
a -> ObjectLockRule
s {$sel:defaultRetention:ObjectLockRule' :: Maybe DefaultRetention
defaultRetention = Maybe DefaultRetention
a} :: ObjectLockRule)

instance Core.FromXML ObjectLockRule where
  parseXML :: [Node] -> Either String ObjectLockRule
parseXML [Node]
x =
    Maybe DefaultRetention -> ObjectLockRule
ObjectLockRule'
      (Maybe DefaultRetention -> ObjectLockRule)
-> Either String (Maybe DefaultRetention)
-> Either String ObjectLockRule
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe DefaultRetention)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"DefaultRetention")

instance Prelude.Hashable ObjectLockRule

instance Prelude.NFData ObjectLockRule

instance Core.ToXML ObjectLockRule where
  toXML :: ObjectLockRule -> XML
toXML ObjectLockRule' {Maybe DefaultRetention
defaultRetention :: Maybe DefaultRetention
$sel:defaultRetention:ObjectLockRule' :: ObjectLockRule -> Maybe DefaultRetention
..} =
    [XML] -> XML
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [Name
"DefaultRetention" Name -> Maybe DefaultRetention -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe DefaultRetention
defaultRetention]