{-# 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-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.ReplicationRuleAndOperator 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.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
(ReplicationRuleAndOperator -> ReplicationRuleAndOperator -> Bool)
-> (ReplicationRuleAndOperator
    -> ReplicationRuleAndOperator -> Bool)
-> Eq ReplicationRuleAndOperator
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]
(Int -> ReadS ReplicationRuleAndOperator)
-> ReadS [ReplicationRuleAndOperator]
-> ReadPrec ReplicationRuleAndOperator
-> ReadPrec [ReplicationRuleAndOperator]
-> Read 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
(Int -> ReplicationRuleAndOperator -> ShowS)
-> (ReplicationRuleAndOperator -> String)
-> ([ReplicationRuleAndOperator] -> ShowS)
-> Show ReplicationRuleAndOperator
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.
 ReplicationRuleAndOperator -> Rep ReplicationRuleAndOperator x)
-> (forall x.
    Rep ReplicationRuleAndOperator x -> ReplicationRuleAndOperator)
-> Generic ReplicationRuleAndOperator
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' :: Maybe Text -> Maybe [Tag] -> ReplicationRuleAndOperator
ReplicationRuleAndOperator'
    { $sel:prefix:ReplicationRuleAndOperator' :: Maybe Text
prefix =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:tags:ReplicationRuleAndOperator' :: Maybe [Tag]
tags = Maybe [Tag]
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 :: (Maybe Text -> f (Maybe Text))
-> ReplicationRuleAndOperator -> f ReplicationRuleAndOperator
replicationRuleAndOperator_prefix = (ReplicationRuleAndOperator -> Maybe Text)
-> (ReplicationRuleAndOperator
    -> Maybe Text -> ReplicationRuleAndOperator)
-> Lens
     ReplicationRuleAndOperator
     ReplicationRuleAndOperator
     (Maybe Text)
     (Maybe Text)
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 :: (Maybe [Tag] -> f (Maybe [Tag]))
-> ReplicationRuleAndOperator -> f ReplicationRuleAndOperator
replicationRuleAndOperator_tags = (ReplicationRuleAndOperator -> Maybe [Tag])
-> (ReplicationRuleAndOperator
    -> Maybe [Tag] -> ReplicationRuleAndOperator)
-> Lens
     ReplicationRuleAndOperator
     ReplicationRuleAndOperator
     (Maybe [Tag])
     (Maybe [Tag])
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) ((Maybe [Tag] -> f (Maybe [Tag]))
 -> ReplicationRuleAndOperator -> f ReplicationRuleAndOperator)
-> ((Maybe [Tag] -> f (Maybe [Tag]))
    -> Maybe [Tag] -> f (Maybe [Tag]))
-> (Maybe [Tag] -> f (Maybe [Tag]))
-> ReplicationRuleAndOperator
-> f ReplicationRuleAndOperator
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Tag] [Tag] [Tag] [Tag]
-> Iso (Maybe [Tag]) (Maybe [Tag]) (Maybe [Tag]) (Maybe [Tag])
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 AnIso [Tag] [Tag] [Tag] [Tag]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable ReplicationRuleAndOperator

instance Prelude.NFData ReplicationRuleAndOperator

instance Core.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
..} =
    [XML] -> XML
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"Prefix" Name -> Maybe Text -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe Text
prefix,
        Name
"Tag"
          Name -> XML -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe XML -> XML
forall a. ToXML a => a -> XML
Core.toXML (Name -> [Tag] -> XML
forall a. (IsList a, ToXML (Item a)) => Name -> a -> XML
Core.toXMLList Name
"Tag" ([Tag] -> XML) -> Maybe [Tag] -> Maybe XML
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Tag]
tags)
      ]