{-# 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.ReplicationRuleAndOperator
-- 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.ReplicationRuleAndOperator 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.Tag

-- | 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.
--
-- /See:/ 'newReplicationRuleAndOperator' smart constructor.
data ReplicationRuleAndOperator = ReplicationRuleAndOperator'
  { -- | An object key name prefix that identifies the subset of objects to which
    -- the rule applies.
    ReplicationRuleAndOperator -> Maybe Text
prefix :: Prelude.Maybe Prelude.Text,
    -- | An array of tags containing key and value pairs.
    ReplicationRuleAndOperator -> Maybe [Tag]
tags :: Prelude.Maybe [Tag]
  }
  deriving (ReplicationRuleAndOperator -> ReplicationRuleAndOperator -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ReplicationRuleAndOperator -> ReplicationRuleAndOperator -> Bool
$c/= :: ReplicationRuleAndOperator -> ReplicationRuleAndOperator -> Bool
== :: ReplicationRuleAndOperator -> ReplicationRuleAndOperator -> Bool
$c== :: ReplicationRuleAndOperator -> ReplicationRuleAndOperator -> Bool
Prelude.Eq, ReadPrec [ReplicationRuleAndOperator]
ReadPrec ReplicationRuleAndOperator
Int -> ReadS ReplicationRuleAndOperator
ReadS [ReplicationRuleAndOperator]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ReplicationRuleAndOperator]
$creadListPrec :: ReadPrec [ReplicationRuleAndOperator]
readPrec :: ReadPrec ReplicationRuleAndOperator
$creadPrec :: ReadPrec ReplicationRuleAndOperator
readList :: ReadS [ReplicationRuleAndOperator]
$creadList :: ReadS [ReplicationRuleAndOperator]
readsPrec :: Int -> ReadS ReplicationRuleAndOperator
$creadsPrec :: Int -> ReadS ReplicationRuleAndOperator
Prelude.Read, Int -> ReplicationRuleAndOperator -> ShowS
[ReplicationRuleAndOperator] -> ShowS
ReplicationRuleAndOperator -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ReplicationRuleAndOperator] -> ShowS
$cshowList :: [ReplicationRuleAndOperator] -> ShowS
show :: ReplicationRuleAndOperator -> String
$cshow :: ReplicationRuleAndOperator -> String
showsPrec :: Int -> ReplicationRuleAndOperator -> ShowS
$cshowsPrec :: Int -> ReplicationRuleAndOperator -> ShowS
Prelude.Show, forall x.
Rep ReplicationRuleAndOperator x -> ReplicationRuleAndOperator
forall x.
ReplicationRuleAndOperator -> Rep ReplicationRuleAndOperator x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ReplicationRuleAndOperator x -> ReplicationRuleAndOperator
$cfrom :: forall x.
ReplicationRuleAndOperator -> Rep ReplicationRuleAndOperator x
Prelude.Generic)

-- |
-- Create a value of 'ReplicationRuleAndOperator' 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:
--
-- 'prefix', 'replicationRuleAndOperator_prefix' - An object key name prefix that identifies the subset of objects to which
-- the rule applies.
--
-- 'tags', 'replicationRuleAndOperator_tags' - An array of tags containing key and value pairs.
newReplicationRuleAndOperator ::
  ReplicationRuleAndOperator
newReplicationRuleAndOperator :: ReplicationRuleAndOperator
newReplicationRuleAndOperator =
  ReplicationRuleAndOperator'
    { $sel:prefix:ReplicationRuleAndOperator' :: Maybe Text
prefix =
        forall a. Maybe a
Prelude.Nothing,
      $sel:tags:ReplicationRuleAndOperator' :: Maybe [Tag]
tags = forall a. Maybe a
Prelude.Nothing
    }

-- | An object key name prefix that identifies the subset of objects to which
-- the rule applies.
replicationRuleAndOperator_prefix :: Lens.Lens' ReplicationRuleAndOperator (Prelude.Maybe Prelude.Text)
replicationRuleAndOperator_prefix :: Lens' ReplicationRuleAndOperator (Maybe Text)
replicationRuleAndOperator_prefix = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ReplicationRuleAndOperator' {Maybe Text
prefix :: Maybe Text
$sel:prefix:ReplicationRuleAndOperator' :: ReplicationRuleAndOperator -> Maybe Text
prefix} -> Maybe Text
prefix) (\s :: ReplicationRuleAndOperator
s@ReplicationRuleAndOperator' {} Maybe Text
a -> ReplicationRuleAndOperator
s {$sel:prefix:ReplicationRuleAndOperator' :: Maybe Text
prefix = Maybe Text
a} :: ReplicationRuleAndOperator)

-- | An array of tags containing key and value pairs.
replicationRuleAndOperator_tags :: Lens.Lens' ReplicationRuleAndOperator (Prelude.Maybe [Tag])
replicationRuleAndOperator_tags :: Lens' ReplicationRuleAndOperator (Maybe [Tag])
replicationRuleAndOperator_tags = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ReplicationRuleAndOperator' {Maybe [Tag]
tags :: Maybe [Tag]
$sel:tags:ReplicationRuleAndOperator' :: ReplicationRuleAndOperator -> Maybe [Tag]
tags} -> Maybe [Tag]
tags) (\s :: ReplicationRuleAndOperator
s@ReplicationRuleAndOperator' {} Maybe [Tag]
a -> ReplicationRuleAndOperator
s {$sel:tags:ReplicationRuleAndOperator' :: Maybe [Tag]
tags = Maybe [Tag]
a} :: ReplicationRuleAndOperator) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Data.FromXML ReplicationRuleAndOperator where
  parseXML :: [Node] -> Either String ReplicationRuleAndOperator
parseXML [Node]
x =
    Maybe Text -> Maybe [Tag] -> ReplicationRuleAndOperator
ReplicationRuleAndOperator'
      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
"Prefix")
      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
"Tag"
                      forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty
                      forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (forall a. FromXML a => Text -> [Node] -> Either String [a]
Data.parseXMLList Text
"Tag")
                  )

instance Prelude.Hashable ReplicationRuleAndOperator where
  hashWithSalt :: Int -> ReplicationRuleAndOperator -> Int
hashWithSalt Int
_salt ReplicationRuleAndOperator' {Maybe [Tag]
Maybe Text
tags :: Maybe [Tag]
prefix :: Maybe Text
$sel:tags:ReplicationRuleAndOperator' :: ReplicationRuleAndOperator -> Maybe [Tag]
$sel:prefix:ReplicationRuleAndOperator' :: ReplicationRuleAndOperator -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
prefix
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Tag]
tags

instance Prelude.NFData ReplicationRuleAndOperator where
  rnf :: ReplicationRuleAndOperator -> ()
rnf ReplicationRuleAndOperator' {Maybe [Tag]
Maybe Text
tags :: Maybe [Tag]
prefix :: Maybe Text
$sel:tags:ReplicationRuleAndOperator' :: ReplicationRuleAndOperator -> Maybe [Tag]
$sel:prefix:ReplicationRuleAndOperator' :: ReplicationRuleAndOperator -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
prefix seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [Tag]
tags

instance Data.ToXML ReplicationRuleAndOperator where
  toXML :: ReplicationRuleAndOperator -> XML
toXML ReplicationRuleAndOperator' {Maybe [Tag]
Maybe Text
tags :: Maybe [Tag]
prefix :: Maybe Text
$sel:tags:ReplicationRuleAndOperator' :: ReplicationRuleAndOperator -> Maybe [Tag]
$sel:prefix:ReplicationRuleAndOperator' :: ReplicationRuleAndOperator -> Maybe Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"Prefix" forall a. ToXML a => Name -> a -> XML
Data.@= Maybe Text
prefix,
        Name
"Tag"
          forall a. ToXML a => Name -> a -> XML
Data.@= forall a. ToXML a => a -> XML
Data.toXML (forall a. (IsList a, ToXML (Item a)) => Name -> a -> XML
Data.toXMLList Name
"Tag" forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Tag]
tags)
      ]