{-# 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.CloudWatch.Types.Metric
-- 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.CloudWatch.Types.Metric where

import Amazonka.CloudWatch.Types.Dimension
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Represents a specific metric.
--
-- /See:/ 'newMetric' smart constructor.
data Metric = Metric'
  { -- | The name of the metric. This is a required field.
    Metric -> Maybe Text
metricName :: Prelude.Maybe Prelude.Text,
    -- | The namespace of the metric.
    Metric -> Maybe Text
namespace :: Prelude.Maybe Prelude.Text,
    -- | The dimensions for the metric.
    Metric -> Maybe [Dimension]
dimensions :: Prelude.Maybe [Dimension]
  }
  deriving (Metric -> Metric -> Bool
(Metric -> Metric -> Bool)
-> (Metric -> Metric -> Bool) -> Eq Metric
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Metric -> Metric -> Bool
$c/= :: Metric -> Metric -> Bool
== :: Metric -> Metric -> Bool
$c== :: Metric -> Metric -> Bool
Prelude.Eq, ReadPrec [Metric]
ReadPrec Metric
Int -> ReadS Metric
ReadS [Metric]
(Int -> ReadS Metric)
-> ReadS [Metric]
-> ReadPrec Metric
-> ReadPrec [Metric]
-> Read Metric
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Metric]
$creadListPrec :: ReadPrec [Metric]
readPrec :: ReadPrec Metric
$creadPrec :: ReadPrec Metric
readList :: ReadS [Metric]
$creadList :: ReadS [Metric]
readsPrec :: Int -> ReadS Metric
$creadsPrec :: Int -> ReadS Metric
Prelude.Read, Int -> Metric -> ShowS
[Metric] -> ShowS
Metric -> String
(Int -> Metric -> ShowS)
-> (Metric -> String) -> ([Metric] -> ShowS) -> Show Metric
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Metric] -> ShowS
$cshowList :: [Metric] -> ShowS
show :: Metric -> String
$cshow :: Metric -> String
showsPrec :: Int -> Metric -> ShowS
$cshowsPrec :: Int -> Metric -> ShowS
Prelude.Show, (forall x. Metric -> Rep Metric x)
-> (forall x. Rep Metric x -> Metric) -> Generic Metric
forall x. Rep Metric x -> Metric
forall x. Metric -> Rep Metric x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Metric x -> Metric
$cfrom :: forall x. Metric -> Rep Metric x
Prelude.Generic)

-- |
-- Create a value of 'Metric' 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:
--
-- 'metricName', 'metric_metricName' - The name of the metric. This is a required field.
--
-- 'namespace', 'metric_namespace' - The namespace of the metric.
--
-- 'dimensions', 'metric_dimensions' - The dimensions for the metric.
newMetric ::
  Metric
newMetric :: Metric
newMetric =
  Metric' :: Maybe Text -> Maybe Text -> Maybe [Dimension] -> Metric
Metric'
    { $sel:metricName:Metric' :: Maybe Text
metricName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:namespace:Metric' :: Maybe Text
namespace = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:dimensions:Metric' :: Maybe [Dimension]
dimensions = Maybe [Dimension]
forall a. Maybe a
Prelude.Nothing
    }

-- | The name of the metric. This is a required field.
metric_metricName :: Lens.Lens' Metric (Prelude.Maybe Prelude.Text)
metric_metricName :: (Maybe Text -> f (Maybe Text)) -> Metric -> f Metric
metric_metricName = (Metric -> Maybe Text)
-> (Metric -> Maybe Text -> Metric)
-> Lens Metric Metric (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Metric' {Maybe Text
metricName :: Maybe Text
$sel:metricName:Metric' :: Metric -> Maybe Text
metricName} -> Maybe Text
metricName) (\s :: Metric
s@Metric' {} Maybe Text
a -> Metric
s {$sel:metricName:Metric' :: Maybe Text
metricName = Maybe Text
a} :: Metric)

-- | The namespace of the metric.
metric_namespace :: Lens.Lens' Metric (Prelude.Maybe Prelude.Text)
metric_namespace :: (Maybe Text -> f (Maybe Text)) -> Metric -> f Metric
metric_namespace = (Metric -> Maybe Text)
-> (Metric -> Maybe Text -> Metric)
-> Lens Metric Metric (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Metric' {Maybe Text
namespace :: Maybe Text
$sel:namespace:Metric' :: Metric -> Maybe Text
namespace} -> Maybe Text
namespace) (\s :: Metric
s@Metric' {} Maybe Text
a -> Metric
s {$sel:namespace:Metric' :: Maybe Text
namespace = Maybe Text
a} :: Metric)

-- | The dimensions for the metric.
metric_dimensions :: Lens.Lens' Metric (Prelude.Maybe [Dimension])
metric_dimensions :: (Maybe [Dimension] -> f (Maybe [Dimension])) -> Metric -> f Metric
metric_dimensions = (Metric -> Maybe [Dimension])
-> (Metric -> Maybe [Dimension] -> Metric)
-> Lens Metric Metric (Maybe [Dimension]) (Maybe [Dimension])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Metric' {Maybe [Dimension]
dimensions :: Maybe [Dimension]
$sel:dimensions:Metric' :: Metric -> Maybe [Dimension]
dimensions} -> Maybe [Dimension]
dimensions) (\s :: Metric
s@Metric' {} Maybe [Dimension]
a -> Metric
s {$sel:dimensions:Metric' :: Maybe [Dimension]
dimensions = Maybe [Dimension]
a} :: Metric) ((Maybe [Dimension] -> f (Maybe [Dimension]))
 -> Metric -> f Metric)
-> ((Maybe [Dimension] -> f (Maybe [Dimension]))
    -> Maybe [Dimension] -> f (Maybe [Dimension]))
-> (Maybe [Dimension] -> f (Maybe [Dimension]))
-> Metric
-> f Metric
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Dimension] [Dimension] [Dimension] [Dimension]
-> Iso
     (Maybe [Dimension])
     (Maybe [Dimension])
     (Maybe [Dimension])
     (Maybe [Dimension])
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 [Dimension] [Dimension] [Dimension] [Dimension]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromXML Metric where
  parseXML :: [Node] -> Either String Metric
parseXML [Node]
x =
    Maybe Text -> Maybe Text -> Maybe [Dimension] -> Metric
Metric'
      (Maybe Text -> Maybe Text -> Maybe [Dimension] -> Metric)
-> Either String (Maybe Text)
-> Either String (Maybe Text -> Maybe [Dimension] -> Metric)
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
"MetricName")
      Either String (Maybe Text -> Maybe [Dimension] -> Metric)
-> Either String (Maybe Text)
-> Either String (Maybe [Dimension] -> Metric)
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
"Namespace")
      Either String (Maybe [Dimension] -> Metric)
-> Either String (Maybe [Dimension]) -> Either String Metric
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
"Dimensions" 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 [Dimension]))
-> Either String (Maybe [Dimension])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= ([Node] -> Either String [Dimension])
-> [Node] -> Either String (Maybe [Dimension])
forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (Text -> [Node] -> Either String [Dimension]
forall a. FromXML a => Text -> [Node] -> Either String [a]
Core.parseXMLList Text
"member")
                  )

instance Prelude.Hashable Metric

instance Prelude.NFData Metric

instance Core.ToQuery Metric where
  toQuery :: Metric -> QueryString
toQuery Metric' {Maybe [Dimension]
Maybe Text
dimensions :: Maybe [Dimension]
namespace :: Maybe Text
metricName :: Maybe Text
$sel:dimensions:Metric' :: Metric -> Maybe [Dimension]
$sel:namespace:Metric' :: Metric -> Maybe Text
$sel:metricName:Metric' :: Metric -> Maybe Text
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"MetricName" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
metricName,
        ByteString
"Namespace" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
namespace,
        ByteString
"Dimensions"
          ByteString -> QueryString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe QueryString -> QueryString
forall a. ToQuery a => a -> QueryString
Core.toQuery
            (ByteString -> [Dimension] -> QueryString
forall a.
(IsList a, ToQuery (Item a)) =>
ByteString -> a -> QueryString
Core.toQueryList ByteString
"member" ([Dimension] -> QueryString)
-> Maybe [Dimension] -> Maybe QueryString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Dimension]
dimensions)
      ]