{-# 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.MetricsConfiguration
-- 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.MetricsConfiguration 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.MetricsFilter

-- | Specifies a metrics configuration for the CloudWatch request metrics
-- (specified by the metrics configuration ID) from an Amazon S3 bucket. If
-- you\'re updating an existing metrics configuration, note that this is a
-- full replacement of the existing metrics configuration. If you don\'t
-- include the elements you want to keep, they are erased. For more
-- information, see
-- <https://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketPUTMetricConfiguration.html PutBucketMetricsConfiguration>.
--
-- /See:/ 'newMetricsConfiguration' smart constructor.
data MetricsConfiguration = MetricsConfiguration'
  { -- | Specifies a metrics configuration filter. The metrics configuration will
    -- only include objects that meet the filter\'s criteria. A filter must be
    -- a prefix, an object tag, an access point ARN, or a conjunction
    -- (MetricsAndOperator).
    MetricsConfiguration -> Maybe MetricsFilter
filter' :: Prelude.Maybe MetricsFilter,
    -- | The ID used to identify the metrics configuration.
    MetricsConfiguration -> Text
id :: Prelude.Text
  }
  deriving (MetricsConfiguration -> MetricsConfiguration -> Bool
(MetricsConfiguration -> MetricsConfiguration -> Bool)
-> (MetricsConfiguration -> MetricsConfiguration -> Bool)
-> Eq MetricsConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MetricsConfiguration -> MetricsConfiguration -> Bool
$c/= :: MetricsConfiguration -> MetricsConfiguration -> Bool
== :: MetricsConfiguration -> MetricsConfiguration -> Bool
$c== :: MetricsConfiguration -> MetricsConfiguration -> Bool
Prelude.Eq, ReadPrec [MetricsConfiguration]
ReadPrec MetricsConfiguration
Int -> ReadS MetricsConfiguration
ReadS [MetricsConfiguration]
(Int -> ReadS MetricsConfiguration)
-> ReadS [MetricsConfiguration]
-> ReadPrec MetricsConfiguration
-> ReadPrec [MetricsConfiguration]
-> Read MetricsConfiguration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MetricsConfiguration]
$creadListPrec :: ReadPrec [MetricsConfiguration]
readPrec :: ReadPrec MetricsConfiguration
$creadPrec :: ReadPrec MetricsConfiguration
readList :: ReadS [MetricsConfiguration]
$creadList :: ReadS [MetricsConfiguration]
readsPrec :: Int -> ReadS MetricsConfiguration
$creadsPrec :: Int -> ReadS MetricsConfiguration
Prelude.Read, Int -> MetricsConfiguration -> ShowS
[MetricsConfiguration] -> ShowS
MetricsConfiguration -> String
(Int -> MetricsConfiguration -> ShowS)
-> (MetricsConfiguration -> String)
-> ([MetricsConfiguration] -> ShowS)
-> Show MetricsConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MetricsConfiguration] -> ShowS
$cshowList :: [MetricsConfiguration] -> ShowS
show :: MetricsConfiguration -> String
$cshow :: MetricsConfiguration -> String
showsPrec :: Int -> MetricsConfiguration -> ShowS
$cshowsPrec :: Int -> MetricsConfiguration -> ShowS
Prelude.Show, (forall x. MetricsConfiguration -> Rep MetricsConfiguration x)
-> (forall x. Rep MetricsConfiguration x -> MetricsConfiguration)
-> Generic MetricsConfiguration
forall x. Rep MetricsConfiguration x -> MetricsConfiguration
forall x. MetricsConfiguration -> Rep MetricsConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MetricsConfiguration x -> MetricsConfiguration
$cfrom :: forall x. MetricsConfiguration -> Rep MetricsConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'MetricsConfiguration' 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:
--
-- 'filter'', 'metricsConfiguration_filter' - Specifies a metrics configuration filter. The metrics configuration will
-- only include objects that meet the filter\'s criteria. A filter must be
-- a prefix, an object tag, an access point ARN, or a conjunction
-- (MetricsAndOperator).
--
-- 'id', 'metricsConfiguration_id' - The ID used to identify the metrics configuration.
newMetricsConfiguration ::
  -- | 'id'
  Prelude.Text ->
  MetricsConfiguration
newMetricsConfiguration :: Text -> MetricsConfiguration
newMetricsConfiguration Text
pId_ =
  MetricsConfiguration' :: Maybe MetricsFilter -> Text -> MetricsConfiguration
MetricsConfiguration'
    { $sel:filter':MetricsConfiguration' :: Maybe MetricsFilter
filter' = Maybe MetricsFilter
forall a. Maybe a
Prelude.Nothing,
      $sel:id:MetricsConfiguration' :: Text
id = Text
pId_
    }

-- | Specifies a metrics configuration filter. The metrics configuration will
-- only include objects that meet the filter\'s criteria. A filter must be
-- a prefix, an object tag, an access point ARN, or a conjunction
-- (MetricsAndOperator).
metricsConfiguration_filter :: Lens.Lens' MetricsConfiguration (Prelude.Maybe MetricsFilter)
metricsConfiguration_filter :: (Maybe MetricsFilter -> f (Maybe MetricsFilter))
-> MetricsConfiguration -> f MetricsConfiguration
metricsConfiguration_filter = (MetricsConfiguration -> Maybe MetricsFilter)
-> (MetricsConfiguration
    -> Maybe MetricsFilter -> MetricsConfiguration)
-> Lens
     MetricsConfiguration
     MetricsConfiguration
     (Maybe MetricsFilter)
     (Maybe MetricsFilter)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricsConfiguration' {Maybe MetricsFilter
filter' :: Maybe MetricsFilter
$sel:filter':MetricsConfiguration' :: MetricsConfiguration -> Maybe MetricsFilter
filter'} -> Maybe MetricsFilter
filter') (\s :: MetricsConfiguration
s@MetricsConfiguration' {} Maybe MetricsFilter
a -> MetricsConfiguration
s {$sel:filter':MetricsConfiguration' :: Maybe MetricsFilter
filter' = Maybe MetricsFilter
a} :: MetricsConfiguration)

-- | The ID used to identify the metrics configuration.
metricsConfiguration_id :: Lens.Lens' MetricsConfiguration Prelude.Text
metricsConfiguration_id :: (Text -> f Text) -> MetricsConfiguration -> f MetricsConfiguration
metricsConfiguration_id = (MetricsConfiguration -> Text)
-> (MetricsConfiguration -> Text -> MetricsConfiguration)
-> Lens MetricsConfiguration MetricsConfiguration Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricsConfiguration' {Text
id :: Text
$sel:id:MetricsConfiguration' :: MetricsConfiguration -> Text
id} -> Text
id) (\s :: MetricsConfiguration
s@MetricsConfiguration' {} Text
a -> MetricsConfiguration
s {$sel:id:MetricsConfiguration' :: Text
id = Text
a} :: MetricsConfiguration)

instance Core.FromXML MetricsConfiguration where
  parseXML :: [Node] -> Either String MetricsConfiguration
parseXML [Node]
x =
    Maybe MetricsFilter -> Text -> MetricsConfiguration
MetricsConfiguration'
      (Maybe MetricsFilter -> Text -> MetricsConfiguration)
-> Either String (Maybe MetricsFilter)
-> Either String (Text -> MetricsConfiguration)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe MetricsFilter)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Filter") Either String (Text -> MetricsConfiguration)
-> Either String Text -> Either String MetricsConfiguration
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Text
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"Id")

instance Prelude.Hashable MetricsConfiguration

instance Prelude.NFData MetricsConfiguration

instance Core.ToXML MetricsConfiguration where
  toXML :: MetricsConfiguration -> XML
toXML MetricsConfiguration' {Maybe MetricsFilter
Text
id :: Text
filter' :: Maybe MetricsFilter
$sel:id:MetricsConfiguration' :: MetricsConfiguration -> Text
$sel:filter':MetricsConfiguration' :: MetricsConfiguration -> Maybe MetricsFilter
..} =
    [XML] -> XML
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [Name
"Filter" Name -> Maybe MetricsFilter -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe MetricsFilter
filter', Name
"Id" Name -> Text -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Text
id]