{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.S3.Types.ObjectLockConfiguration where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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]
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
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. 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'
    { $sel:objectLockEnabled:ObjectLockConfiguration' :: Maybe ObjectLockEnabled
objectLockEnabled =
        forall a. Maybe a
Prelude.Nothing,
      $sel:rule:ObjectLockConfiguration' :: Maybe ObjectLockRule
rule = 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 :: Lens' ObjectLockConfiguration (Maybe ObjectLockEnabled)
objectLockConfiguration_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 :: Lens' ObjectLockConfiguration (Maybe ObjectLockRule)
objectLockConfiguration_rule = 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 Data.FromXML ObjectLockConfiguration where
  parseXML :: [Node] -> Either String ObjectLockConfiguration
parseXML [Node]
x =
    Maybe ObjectLockEnabled
-> Maybe ObjectLockRule -> ObjectLockConfiguration
ObjectLockConfiguration'
      forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"ObjectLockEnabled")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"Rule")

instance Prelude.Hashable ObjectLockConfiguration where
  hashWithSalt :: Int -> ObjectLockConfiguration -> Int
hashWithSalt Int
_salt ObjectLockConfiguration' {Maybe ObjectLockEnabled
Maybe ObjectLockRule
rule :: Maybe ObjectLockRule
objectLockEnabled :: Maybe ObjectLockEnabled
$sel:rule:ObjectLockConfiguration' :: ObjectLockConfiguration -> Maybe ObjectLockRule
$sel:objectLockEnabled:ObjectLockConfiguration' :: ObjectLockConfiguration -> Maybe ObjectLockEnabled
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ObjectLockEnabled
objectLockEnabled
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ObjectLockRule
rule

instance Prelude.NFData ObjectLockConfiguration where
  rnf :: ObjectLockConfiguration -> ()
rnf ObjectLockConfiguration' {Maybe ObjectLockEnabled
Maybe ObjectLockRule
rule :: Maybe ObjectLockRule
objectLockEnabled :: Maybe ObjectLockEnabled
$sel:rule:ObjectLockConfiguration' :: ObjectLockConfiguration -> Maybe ObjectLockRule
$sel:objectLockEnabled:ObjectLockConfiguration' :: ObjectLockConfiguration -> Maybe ObjectLockEnabled
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe ObjectLockEnabled
objectLockEnabled
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe ObjectLockRule
rule

instance Data.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
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"ObjectLockEnabled" forall a. ToXML a => Name -> a -> XML
Data.@= Maybe ObjectLockEnabled
objectLockEnabled,
        Name
"Rule" forall a. ToXML a => Name -> a -> XML
Data.@= Maybe ObjectLockRule
rule
      ]