{-# 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.AnalyticsAndOperator
-- 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.AnalyticsAndOperator 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 conjunction (logical AND) of predicates, which is used in evaluating a
-- metrics filter. The operator must have at least two predicates in any
-- combination, and an object must match all of the predicates for the
-- filter to apply.
--
-- /See:/ 'newAnalyticsAndOperator' smart constructor.
data AnalyticsAndOperator = AnalyticsAndOperator'
  { -- | The prefix to use when evaluating an AND predicate: The prefix that an
    -- object must have to be included in the metrics results.
    AnalyticsAndOperator -> Maybe Text
prefix :: Prelude.Maybe Prelude.Text,
    -- | The list of tags to use when evaluating an AND predicate.
    AnalyticsAndOperator -> Maybe [Tag]
tags :: Prelude.Maybe [Tag]
  }
  deriving (AnalyticsAndOperator -> AnalyticsAndOperator -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AnalyticsAndOperator -> AnalyticsAndOperator -> Bool
$c/= :: AnalyticsAndOperator -> AnalyticsAndOperator -> Bool
== :: AnalyticsAndOperator -> AnalyticsAndOperator -> Bool
$c== :: AnalyticsAndOperator -> AnalyticsAndOperator -> Bool
Prelude.Eq, ReadPrec [AnalyticsAndOperator]
ReadPrec AnalyticsAndOperator
Int -> ReadS AnalyticsAndOperator
ReadS [AnalyticsAndOperator]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AnalyticsAndOperator]
$creadListPrec :: ReadPrec [AnalyticsAndOperator]
readPrec :: ReadPrec AnalyticsAndOperator
$creadPrec :: ReadPrec AnalyticsAndOperator
readList :: ReadS [AnalyticsAndOperator]
$creadList :: ReadS [AnalyticsAndOperator]
readsPrec :: Int -> ReadS AnalyticsAndOperator
$creadsPrec :: Int -> ReadS AnalyticsAndOperator
Prelude.Read, Int -> AnalyticsAndOperator -> ShowS
[AnalyticsAndOperator] -> ShowS
AnalyticsAndOperator -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AnalyticsAndOperator] -> ShowS
$cshowList :: [AnalyticsAndOperator] -> ShowS
show :: AnalyticsAndOperator -> String
$cshow :: AnalyticsAndOperator -> String
showsPrec :: Int -> AnalyticsAndOperator -> ShowS
$cshowsPrec :: Int -> AnalyticsAndOperator -> ShowS
Prelude.Show, forall x. Rep AnalyticsAndOperator x -> AnalyticsAndOperator
forall x. AnalyticsAndOperator -> Rep AnalyticsAndOperator x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AnalyticsAndOperator x -> AnalyticsAndOperator
$cfrom :: forall x. AnalyticsAndOperator -> Rep AnalyticsAndOperator x
Prelude.Generic)

-- |
-- Create a value of 'AnalyticsAndOperator' 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', 'analyticsAndOperator_prefix' - The prefix to use when evaluating an AND predicate: The prefix that an
-- object must have to be included in the metrics results.
--
-- 'tags', 'analyticsAndOperator_tags' - The list of tags to use when evaluating an AND predicate.
newAnalyticsAndOperator ::
  AnalyticsAndOperator
newAnalyticsAndOperator :: AnalyticsAndOperator
newAnalyticsAndOperator =
  AnalyticsAndOperator'
    { $sel:prefix:AnalyticsAndOperator' :: Maybe Text
prefix = forall a. Maybe a
Prelude.Nothing,
      $sel:tags:AnalyticsAndOperator' :: Maybe [Tag]
tags = forall a. Maybe a
Prelude.Nothing
    }

-- | The prefix to use when evaluating an AND predicate: The prefix that an
-- object must have to be included in the metrics results.
analyticsAndOperator_prefix :: Lens.Lens' AnalyticsAndOperator (Prelude.Maybe Prelude.Text)
analyticsAndOperator_prefix :: Lens' AnalyticsAndOperator (Maybe Text)
analyticsAndOperator_prefix = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AnalyticsAndOperator' {Maybe Text
prefix :: Maybe Text
$sel:prefix:AnalyticsAndOperator' :: AnalyticsAndOperator -> Maybe Text
prefix} -> Maybe Text
prefix) (\s :: AnalyticsAndOperator
s@AnalyticsAndOperator' {} Maybe Text
a -> AnalyticsAndOperator
s {$sel:prefix:AnalyticsAndOperator' :: Maybe Text
prefix = Maybe Text
a} :: AnalyticsAndOperator)

-- | The list of tags to use when evaluating an AND predicate.
analyticsAndOperator_tags :: Lens.Lens' AnalyticsAndOperator (Prelude.Maybe [Tag])
analyticsAndOperator_tags :: Lens' AnalyticsAndOperator (Maybe [Tag])
analyticsAndOperator_tags = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AnalyticsAndOperator' {Maybe [Tag]
tags :: Maybe [Tag]
$sel:tags:AnalyticsAndOperator' :: AnalyticsAndOperator -> Maybe [Tag]
tags} -> Maybe [Tag]
tags) (\s :: AnalyticsAndOperator
s@AnalyticsAndOperator' {} Maybe [Tag]
a -> AnalyticsAndOperator
s {$sel:tags:AnalyticsAndOperator' :: Maybe [Tag]
tags = Maybe [Tag]
a} :: AnalyticsAndOperator) 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 AnalyticsAndOperator where
  parseXML :: [Node] -> Either String AnalyticsAndOperator
parseXML [Node]
x =
    Maybe Text -> Maybe [Tag] -> AnalyticsAndOperator
AnalyticsAndOperator'
      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 AnalyticsAndOperator where
  hashWithSalt :: Int -> AnalyticsAndOperator -> Int
hashWithSalt Int
_salt AnalyticsAndOperator' {Maybe [Tag]
Maybe Text
tags :: Maybe [Tag]
prefix :: Maybe Text
$sel:tags:AnalyticsAndOperator' :: AnalyticsAndOperator -> Maybe [Tag]
$sel:prefix:AnalyticsAndOperator' :: AnalyticsAndOperator -> 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 AnalyticsAndOperator where
  rnf :: AnalyticsAndOperator -> ()
rnf AnalyticsAndOperator' {Maybe [Tag]
Maybe Text
tags :: Maybe [Tag]
prefix :: Maybe Text
$sel:tags:AnalyticsAndOperator' :: AnalyticsAndOperator -> Maybe [Tag]
$sel:prefix:AnalyticsAndOperator' :: AnalyticsAndOperator -> 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 AnalyticsAndOperator where
  toXML :: AnalyticsAndOperator -> XML
toXML AnalyticsAndOperator' {Maybe [Tag]
Maybe Text
tags :: Maybe [Tag]
prefix :: Maybe Text
$sel:tags:AnalyticsAndOperator' :: AnalyticsAndOperator -> Maybe [Tag]
$sel:prefix:AnalyticsAndOperator' :: AnalyticsAndOperator -> 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)
      ]