{-# 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.ObjectLockConfiguration
-- 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.ObjectLockConfiguration 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.ObjectLockEnabled
import Amazonka.S3.Types.ObjectLockRule

-- | The container element for Object Lock configuration parameters.
--
-- /See:/ 'newObjectLockConfiguration' smart constructor.
data ObjectLockConfiguration = ObjectLockConfiguration'
  { -- | Indicates whether this bucket has an Object Lock configuration enabled.
    -- Enable @ObjectLockEnabled@ when you apply @ObjectLockConfiguration@ to a
    -- bucket.
    ObjectLockConfiguration -> Maybe ObjectLockEnabled
objectLockEnabled :: Prelude.Maybe ObjectLockEnabled,
    -- | Specifies the Object Lock rule for the specified object. Enable the this
    -- rule when you apply @ObjectLockConfiguration@ to a 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.
    ObjectLockConfiguration -> Maybe ObjectLockRule
rule :: Prelude.Maybe ObjectLockRule
  }
  deriving (ObjectLockConfiguration -> ObjectLockConfiguration -> Bool
(ObjectLockConfiguration -> ObjectLockConfiguration -> Bool)
-> (ObjectLockConfiguration -> ObjectLockConfiguration -> Bool)
-> Eq ObjectLockConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ObjectLockConfiguration -> ObjectLockConfiguration -> Bool
$c/= :: ObjectLockConfiguration -> ObjectLockConfiguration -> Bool
== :: ObjectLockConfiguration -> ObjectLockConfiguration -> Bool
$c== :: ObjectLockConfiguration -> ObjectLockConfiguration -> Bool
Prelude.Eq, ReadPrec [ObjectLockConfiguration]
ReadPrec ObjectLockConfiguration
Int -> ReadS ObjectLockConfiguration
ReadS [ObjectLockConfiguration]
(Int -> ReadS ObjectLockConfiguration)
-> ReadS [ObjectLockConfiguration]
-> ReadPrec ObjectLockConfiguration
-> ReadPrec [ObjectLockConfiguration]
-> Read ObjectLockConfiguration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ObjectLockConfiguration]
$creadListPrec :: ReadPrec [ObjectLockConfiguration]
readPrec :: ReadPrec ObjectLockConfiguration
$creadPrec :: ReadPrec ObjectLockConfiguration
readList :: ReadS [ObjectLockConfiguration]
$creadList :: ReadS [ObjectLockConfiguration]
readsPrec :: Int -> ReadS ObjectLockConfiguration
$creadsPrec :: Int -> ReadS ObjectLockConfiguration
Prelude.Read, Int -> ObjectLockConfiguration -> ShowS
[ObjectLockConfiguration] -> ShowS
ObjectLockConfiguration -> String
(Int -> ObjectLockConfiguration -> ShowS)
-> (ObjectLockConfiguration -> String)
-> ([ObjectLockConfiguration] -> ShowS)
-> Show ObjectLockConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ObjectLockConfiguration] -> ShowS
$cshowList :: [ObjectLockConfiguration] -> ShowS
show :: ObjectLockConfiguration -> String
$cshow :: ObjectLockConfiguration -> String
showsPrec :: Int -> ObjectLockConfiguration -> ShowS
$cshowsPrec :: Int -> ObjectLockConfiguration -> ShowS
Prelude.Show, (forall x.
 ObjectLockConfiguration -> Rep ObjectLockConfiguration x)
-> (forall x.
    Rep ObjectLockConfiguration x -> ObjectLockConfiguration)
-> Generic ObjectLockConfiguration
forall x. Rep ObjectLockConfiguration x -> ObjectLockConfiguration
forall x. ObjectLockConfiguration -> Rep ObjectLockConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ObjectLockConfiguration x -> ObjectLockConfiguration
$cfrom :: forall x. ObjectLockConfiguration -> Rep ObjectLockConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'ObjectLockConfiguration' 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:
--
-- 'objectLockEnabled', 'objectLockConfiguration_objectLockEnabled' - Indicates whether this bucket has an Object Lock configuration enabled.
-- Enable @ObjectLockEnabled@ when you apply @ObjectLockConfiguration@ to a
-- bucket.
--
-- 'rule', 'objectLockConfiguration_rule' - Specifies the Object Lock rule for the specified object. Enable the this
-- rule when you apply @ObjectLockConfiguration@ to a 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.
newObjectLockConfiguration ::
  ObjectLockConfiguration
newObjectLockConfiguration :: ObjectLockConfiguration
newObjectLockConfiguration =
  ObjectLockConfiguration' :: Maybe ObjectLockEnabled
-> Maybe ObjectLockRule -> ObjectLockConfiguration
ObjectLockConfiguration'
    { $sel:objectLockEnabled:ObjectLockConfiguration' :: Maybe ObjectLockEnabled
objectLockEnabled =
        Maybe ObjectLockEnabled
forall a. Maybe a
Prelude.Nothing,
      $sel:rule:ObjectLockConfiguration' :: Maybe ObjectLockRule
rule = Maybe ObjectLockRule
forall a. Maybe a
Prelude.Nothing
    }

-- | Indicates whether this bucket has an Object Lock configuration enabled.
-- Enable @ObjectLockEnabled@ when you apply @ObjectLockConfiguration@ to a
-- bucket.
objectLockConfiguration_objectLockEnabled :: Lens.Lens' ObjectLockConfiguration (Prelude.Maybe ObjectLockEnabled)
objectLockConfiguration_objectLockEnabled :: (Maybe ObjectLockEnabled -> f (Maybe ObjectLockEnabled))
-> ObjectLockConfiguration -> f ObjectLockConfiguration
objectLockConfiguration_objectLockEnabled = (ObjectLockConfiguration -> Maybe ObjectLockEnabled)
-> (ObjectLockConfiguration
    -> Maybe ObjectLockEnabled -> ObjectLockConfiguration)
-> Lens
     ObjectLockConfiguration
     ObjectLockConfiguration
     (Maybe ObjectLockEnabled)
     (Maybe ObjectLockEnabled)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ObjectLockConfiguration' {Maybe ObjectLockEnabled
objectLockEnabled :: Maybe ObjectLockEnabled
$sel:objectLockEnabled:ObjectLockConfiguration' :: ObjectLockConfiguration -> Maybe ObjectLockEnabled
objectLockEnabled} -> Maybe ObjectLockEnabled
objectLockEnabled) (\s :: ObjectLockConfiguration
s@ObjectLockConfiguration' {} Maybe ObjectLockEnabled
a -> ObjectLockConfiguration
s {$sel:objectLockEnabled:ObjectLockConfiguration' :: Maybe ObjectLockEnabled
objectLockEnabled = Maybe ObjectLockEnabled
a} :: ObjectLockConfiguration)

-- | Specifies the Object Lock rule for the specified object. Enable the this
-- rule when you apply @ObjectLockConfiguration@ to a 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.
objectLockConfiguration_rule :: Lens.Lens' ObjectLockConfiguration (Prelude.Maybe ObjectLockRule)
objectLockConfiguration_rule :: (Maybe ObjectLockRule -> f (Maybe ObjectLockRule))
-> ObjectLockConfiguration -> f ObjectLockConfiguration
objectLockConfiguration_rule = (ObjectLockConfiguration -> Maybe ObjectLockRule)
-> (ObjectLockConfiguration
    -> Maybe ObjectLockRule -> ObjectLockConfiguration)
-> Lens
     ObjectLockConfiguration
     ObjectLockConfiguration
     (Maybe ObjectLockRule)
     (Maybe ObjectLockRule)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ObjectLockConfiguration' {Maybe ObjectLockRule
rule :: Maybe ObjectLockRule
$sel:rule:ObjectLockConfiguration' :: ObjectLockConfiguration -> Maybe ObjectLockRule
rule} -> Maybe ObjectLockRule
rule) (\s :: ObjectLockConfiguration
s@ObjectLockConfiguration' {} Maybe ObjectLockRule
a -> ObjectLockConfiguration
s {$sel:rule:ObjectLockConfiguration' :: Maybe ObjectLockRule
rule = Maybe ObjectLockRule
a} :: ObjectLockConfiguration)

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

instance Prelude.Hashable ObjectLockConfiguration

instance Prelude.NFData ObjectLockConfiguration

instance Core.ToXML ObjectLockConfiguration where
  toXML :: ObjectLockConfiguration -> XML
toXML ObjectLockConfiguration' {Maybe ObjectLockEnabled
Maybe ObjectLockRule
rule :: Maybe ObjectLockRule
objectLockEnabled :: Maybe ObjectLockEnabled
$sel:rule:ObjectLockConfiguration' :: ObjectLockConfiguration -> Maybe ObjectLockRule
$sel:objectLockEnabled:ObjectLockConfiguration' :: ObjectLockConfiguration -> Maybe ObjectLockEnabled
..} =
    [XML] -> XML
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"ObjectLockEnabled" Name -> Maybe ObjectLockEnabled -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe ObjectLockEnabled
objectLockEnabled,
        Name
"Rule" Name -> Maybe ObjectLockRule -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe ObjectLockRule
rule
      ]