{-# 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.ReplicationRuleFilter
-- 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.ReplicationRuleFilter 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.ReplicationRuleAndOperator
import Amazonka.S3.Types.Tag

-- | A filter that identifies the subset of objects to which the replication
-- rule applies. A @Filter@ must specify exactly one @Prefix@, @Tag@, or an
-- @And@ child element.
--
-- /See:/ 'newReplicationRuleFilter' smart constructor.
data ReplicationRuleFilter = ReplicationRuleFilter'
  { -- | A container for specifying a tag key and value.
    --
    -- The rule applies only to objects that have the tag in their tag set.
    ReplicationRuleFilter -> Maybe Tag
tag :: Prelude.Maybe Tag,
    -- | An object key name prefix that identifies the subset of objects to which
    -- the rule applies.
    --
    -- Replacement must be made for object keys containing special characters
    -- (such as carriage returns) when using XML requests. For more
    -- information, see
    -- <https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-keys.html#object-key-xml-related-constraints XML related object key constraints>.
    ReplicationRuleFilter -> Maybe Text
prefix :: Prelude.Maybe Prelude.Text,
    -- | A container for specifying rule filters. The filters determine the
    -- subset of objects to which the rule applies. This element is required
    -- only if you specify more than one filter. For example:
    --
    -- -   If you specify both a @Prefix@ and a @Tag@ filter, wrap these
    --     filters in an @And@ tag.
    --
    -- -   If you specify a filter based on multiple tags, wrap the @Tag@
    --     elements in an @And@ tag.
    ReplicationRuleFilter -> Maybe ReplicationRuleAndOperator
and :: Prelude.Maybe ReplicationRuleAndOperator
  }
  deriving (ReplicationRuleFilter -> ReplicationRuleFilter -> Bool
(ReplicationRuleFilter -> ReplicationRuleFilter -> Bool)
-> (ReplicationRuleFilter -> ReplicationRuleFilter -> Bool)
-> Eq ReplicationRuleFilter
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ReplicationRuleFilter -> ReplicationRuleFilter -> Bool
$c/= :: ReplicationRuleFilter -> ReplicationRuleFilter -> Bool
== :: ReplicationRuleFilter -> ReplicationRuleFilter -> Bool
$c== :: ReplicationRuleFilter -> ReplicationRuleFilter -> Bool
Prelude.Eq, ReadPrec [ReplicationRuleFilter]
ReadPrec ReplicationRuleFilter
Int -> ReadS ReplicationRuleFilter
ReadS [ReplicationRuleFilter]
(Int -> ReadS ReplicationRuleFilter)
-> ReadS [ReplicationRuleFilter]
-> ReadPrec ReplicationRuleFilter
-> ReadPrec [ReplicationRuleFilter]
-> Read ReplicationRuleFilter
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ReplicationRuleFilter]
$creadListPrec :: ReadPrec [ReplicationRuleFilter]
readPrec :: ReadPrec ReplicationRuleFilter
$creadPrec :: ReadPrec ReplicationRuleFilter
readList :: ReadS [ReplicationRuleFilter]
$creadList :: ReadS [ReplicationRuleFilter]
readsPrec :: Int -> ReadS ReplicationRuleFilter
$creadsPrec :: Int -> ReadS ReplicationRuleFilter
Prelude.Read, Int -> ReplicationRuleFilter -> ShowS
[ReplicationRuleFilter] -> ShowS
ReplicationRuleFilter -> String
(Int -> ReplicationRuleFilter -> ShowS)
-> (ReplicationRuleFilter -> String)
-> ([ReplicationRuleFilter] -> ShowS)
-> Show ReplicationRuleFilter
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ReplicationRuleFilter] -> ShowS
$cshowList :: [ReplicationRuleFilter] -> ShowS
show :: ReplicationRuleFilter -> String
$cshow :: ReplicationRuleFilter -> String
showsPrec :: Int -> ReplicationRuleFilter -> ShowS
$cshowsPrec :: Int -> ReplicationRuleFilter -> ShowS
Prelude.Show, (forall x. ReplicationRuleFilter -> Rep ReplicationRuleFilter x)
-> (forall x. Rep ReplicationRuleFilter x -> ReplicationRuleFilter)
-> Generic ReplicationRuleFilter
forall x. Rep ReplicationRuleFilter x -> ReplicationRuleFilter
forall x. ReplicationRuleFilter -> Rep ReplicationRuleFilter x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ReplicationRuleFilter x -> ReplicationRuleFilter
$cfrom :: forall x. ReplicationRuleFilter -> Rep ReplicationRuleFilter x
Prelude.Generic)

-- |
-- Create a value of 'ReplicationRuleFilter' 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:
--
-- 'tag', 'replicationRuleFilter_tag' - A container for specifying a tag key and value.
--
-- The rule applies only to objects that have the tag in their tag set.
--
-- 'prefix', 'replicationRuleFilter_prefix' - An object key name prefix that identifies the subset of objects to which
-- the rule applies.
--
-- Replacement must be made for object keys containing special characters
-- (such as carriage returns) when using XML requests. For more
-- information, see
-- <https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-keys.html#object-key-xml-related-constraints XML related object key constraints>.
--
-- 'and', 'replicationRuleFilter_and' - A container for specifying rule filters. The filters determine the
-- subset of objects to which the rule applies. This element is required
-- only if you specify more than one filter. For example:
--
-- -   If you specify both a @Prefix@ and a @Tag@ filter, wrap these
--     filters in an @And@ tag.
--
-- -   If you specify a filter based on multiple tags, wrap the @Tag@
--     elements in an @And@ tag.
newReplicationRuleFilter ::
  ReplicationRuleFilter
newReplicationRuleFilter :: ReplicationRuleFilter
newReplicationRuleFilter =
  ReplicationRuleFilter' :: Maybe Tag
-> Maybe Text
-> Maybe ReplicationRuleAndOperator
-> ReplicationRuleFilter
ReplicationRuleFilter'
    { $sel:tag:ReplicationRuleFilter' :: Maybe Tag
tag = Maybe Tag
forall a. Maybe a
Prelude.Nothing,
      $sel:prefix:ReplicationRuleFilter' :: Maybe Text
prefix = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:and:ReplicationRuleFilter' :: Maybe ReplicationRuleAndOperator
and = Maybe ReplicationRuleAndOperator
forall a. Maybe a
Prelude.Nothing
    }

-- | A container for specifying a tag key and value.
--
-- The rule applies only to objects that have the tag in their tag set.
replicationRuleFilter_tag :: Lens.Lens' ReplicationRuleFilter (Prelude.Maybe Tag)
replicationRuleFilter_tag :: (Maybe Tag -> f (Maybe Tag))
-> ReplicationRuleFilter -> f ReplicationRuleFilter
replicationRuleFilter_tag = (ReplicationRuleFilter -> Maybe Tag)
-> (ReplicationRuleFilter -> Maybe Tag -> ReplicationRuleFilter)
-> Lens
     ReplicationRuleFilter ReplicationRuleFilter (Maybe Tag) (Maybe Tag)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ReplicationRuleFilter' {Maybe Tag
tag :: Maybe Tag
$sel:tag:ReplicationRuleFilter' :: ReplicationRuleFilter -> Maybe Tag
tag} -> Maybe Tag
tag) (\s :: ReplicationRuleFilter
s@ReplicationRuleFilter' {} Maybe Tag
a -> ReplicationRuleFilter
s {$sel:tag:ReplicationRuleFilter' :: Maybe Tag
tag = Maybe Tag
a} :: ReplicationRuleFilter)

-- | An object key name prefix that identifies the subset of objects to which
-- the rule applies.
--
-- Replacement must be made for object keys containing special characters
-- (such as carriage returns) when using XML requests. For more
-- information, see
-- <https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-keys.html#object-key-xml-related-constraints XML related object key constraints>.
replicationRuleFilter_prefix :: Lens.Lens' ReplicationRuleFilter (Prelude.Maybe Prelude.Text)
replicationRuleFilter_prefix :: (Maybe Text -> f (Maybe Text))
-> ReplicationRuleFilter -> f ReplicationRuleFilter
replicationRuleFilter_prefix = (ReplicationRuleFilter -> Maybe Text)
-> (ReplicationRuleFilter -> Maybe Text -> ReplicationRuleFilter)
-> Lens
     ReplicationRuleFilter
     ReplicationRuleFilter
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ReplicationRuleFilter' {Maybe Text
prefix :: Maybe Text
$sel:prefix:ReplicationRuleFilter' :: ReplicationRuleFilter -> Maybe Text
prefix} -> Maybe Text
prefix) (\s :: ReplicationRuleFilter
s@ReplicationRuleFilter' {} Maybe Text
a -> ReplicationRuleFilter
s {$sel:prefix:ReplicationRuleFilter' :: Maybe Text
prefix = Maybe Text
a} :: ReplicationRuleFilter)

-- | A container for specifying rule filters. The filters determine the
-- subset of objects to which the rule applies. This element is required
-- only if you specify more than one filter. For example:
--
-- -   If you specify both a @Prefix@ and a @Tag@ filter, wrap these
--     filters in an @And@ tag.
--
-- -   If you specify a filter based on multiple tags, wrap the @Tag@
--     elements in an @And@ tag.
replicationRuleFilter_and :: Lens.Lens' ReplicationRuleFilter (Prelude.Maybe ReplicationRuleAndOperator)
replicationRuleFilter_and :: (Maybe ReplicationRuleAndOperator
 -> f (Maybe ReplicationRuleAndOperator))
-> ReplicationRuleFilter -> f ReplicationRuleFilter
replicationRuleFilter_and = (ReplicationRuleFilter -> Maybe ReplicationRuleAndOperator)
-> (ReplicationRuleFilter
    -> Maybe ReplicationRuleAndOperator -> ReplicationRuleFilter)
-> Lens
     ReplicationRuleFilter
     ReplicationRuleFilter
     (Maybe ReplicationRuleAndOperator)
     (Maybe ReplicationRuleAndOperator)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ReplicationRuleFilter' {Maybe ReplicationRuleAndOperator
and :: Maybe ReplicationRuleAndOperator
$sel:and:ReplicationRuleFilter' :: ReplicationRuleFilter -> Maybe ReplicationRuleAndOperator
and} -> Maybe ReplicationRuleAndOperator
and) (\s :: ReplicationRuleFilter
s@ReplicationRuleFilter' {} Maybe ReplicationRuleAndOperator
a -> ReplicationRuleFilter
s {$sel:and:ReplicationRuleFilter' :: Maybe ReplicationRuleAndOperator
and = Maybe ReplicationRuleAndOperator
a} :: ReplicationRuleFilter)

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

instance Prelude.Hashable ReplicationRuleFilter

instance Prelude.NFData ReplicationRuleFilter

instance Core.ToXML ReplicationRuleFilter where
  toXML :: ReplicationRuleFilter -> XML
toXML ReplicationRuleFilter' {Maybe Text
Maybe Tag
Maybe ReplicationRuleAndOperator
and :: Maybe ReplicationRuleAndOperator
prefix :: Maybe Text
tag :: Maybe Tag
$sel:and:ReplicationRuleFilter' :: ReplicationRuleFilter -> Maybe ReplicationRuleAndOperator
$sel:prefix:ReplicationRuleFilter' :: ReplicationRuleFilter -> Maybe Text
$sel:tag:ReplicationRuleFilter' :: ReplicationRuleFilter -> Maybe Tag
..} =
    [XML] -> XML
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"Tag" Name -> Maybe Tag -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe Tag
tag,
        Name
"Prefix" Name -> Maybe Text -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe Text
prefix,
        Name
"And" Name -> Maybe ReplicationRuleAndOperator -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe ReplicationRuleAndOperator
and
      ]