{-# 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.AutoScaling.Types.MetricStat
-- 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.AutoScaling.Types.MetricStat where

import Amazonka.AutoScaling.Types.Metric
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

-- | This structure defines the CloudWatch metric to return, along with the
-- statistic, period, and unit.
--
-- For more information about the CloudWatch terminology below, see
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_concepts.html Amazon CloudWatch concepts>
-- in the /Amazon CloudWatch User Guide/.
--
-- /See:/ 'newMetricStat' smart constructor.
data MetricStat = MetricStat'
  { -- | The unit to use for the returned data points. For a complete list of the
    -- units that CloudWatch supports, see the
    -- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_MetricDatum.html MetricDatum>
    -- data type in the /Amazon CloudWatch API Reference/.
    MetricStat -> Maybe Text
unit :: Prelude.Maybe Prelude.Text,
    -- | The CloudWatch metric to return, including the metric name, namespace,
    -- and dimensions. To get the exact metric name, namespace, and dimensions,
    -- inspect the
    -- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_Metric.html Metric>
    -- object that is returned by a call to
    -- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_ListMetrics.html ListMetrics>.
    MetricStat -> Metric
metric :: Metric,
    -- | The statistic to return. It can include any CloudWatch statistic or
    -- extended statistic. For a list of valid values, see the table in
    -- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_concepts.html#Statistic Statistics>
    -- in the /Amazon CloudWatch User Guide/.
    --
    -- The most commonly used metrics for predictive scaling are @Average@ and
    -- @Sum@.
    MetricStat -> Text
stat :: Prelude.Text
  }
  deriving (MetricStat -> MetricStat -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MetricStat -> MetricStat -> Bool
$c/= :: MetricStat -> MetricStat -> Bool
== :: MetricStat -> MetricStat -> Bool
$c== :: MetricStat -> MetricStat -> Bool
Prelude.Eq, ReadPrec [MetricStat]
ReadPrec MetricStat
Int -> ReadS MetricStat
ReadS [MetricStat]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MetricStat]
$creadListPrec :: ReadPrec [MetricStat]
readPrec :: ReadPrec MetricStat
$creadPrec :: ReadPrec MetricStat
readList :: ReadS [MetricStat]
$creadList :: ReadS [MetricStat]
readsPrec :: Int -> ReadS MetricStat
$creadsPrec :: Int -> ReadS MetricStat
Prelude.Read, Int -> MetricStat -> ShowS
[MetricStat] -> ShowS
MetricStat -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MetricStat] -> ShowS
$cshowList :: [MetricStat] -> ShowS
show :: MetricStat -> String
$cshow :: MetricStat -> String
showsPrec :: Int -> MetricStat -> ShowS
$cshowsPrec :: Int -> MetricStat -> ShowS
Prelude.Show, forall x. Rep MetricStat x -> MetricStat
forall x. MetricStat -> Rep MetricStat x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MetricStat x -> MetricStat
$cfrom :: forall x. MetricStat -> Rep MetricStat x
Prelude.Generic)

-- |
-- Create a value of 'MetricStat' 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:
--
-- 'unit', 'metricStat_unit' - The unit to use for the returned data points. For a complete list of the
-- units that CloudWatch supports, see the
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_MetricDatum.html MetricDatum>
-- data type in the /Amazon CloudWatch API Reference/.
--
-- 'metric', 'metricStat_metric' - The CloudWatch metric to return, including the metric name, namespace,
-- and dimensions. To get the exact metric name, namespace, and dimensions,
-- inspect the
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_Metric.html Metric>
-- object that is returned by a call to
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_ListMetrics.html ListMetrics>.
--
-- 'stat', 'metricStat_stat' - The statistic to return. It can include any CloudWatch statistic or
-- extended statistic. For a list of valid values, see the table in
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_concepts.html#Statistic Statistics>
-- in the /Amazon CloudWatch User Guide/.
--
-- The most commonly used metrics for predictive scaling are @Average@ and
-- @Sum@.
newMetricStat ::
  -- | 'metric'
  Metric ->
  -- | 'stat'
  Prelude.Text ->
  MetricStat
newMetricStat :: Metric -> Text -> MetricStat
newMetricStat Metric
pMetric_ Text
pStat_ =
  MetricStat'
    { $sel:unit:MetricStat' :: Maybe Text
unit = forall a. Maybe a
Prelude.Nothing,
      $sel:metric:MetricStat' :: Metric
metric = Metric
pMetric_,
      $sel:stat:MetricStat' :: Text
stat = Text
pStat_
    }

-- | The unit to use for the returned data points. For a complete list of the
-- units that CloudWatch supports, see the
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_MetricDatum.html MetricDatum>
-- data type in the /Amazon CloudWatch API Reference/.
metricStat_unit :: Lens.Lens' MetricStat (Prelude.Maybe Prelude.Text)
metricStat_unit :: Lens' MetricStat (Maybe Text)
metricStat_unit = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricStat' {Maybe Text
unit :: Maybe Text
$sel:unit:MetricStat' :: MetricStat -> Maybe Text
unit} -> Maybe Text
unit) (\s :: MetricStat
s@MetricStat' {} Maybe Text
a -> MetricStat
s {$sel:unit:MetricStat' :: Maybe Text
unit = Maybe Text
a} :: MetricStat)

-- | The CloudWatch metric to return, including the metric name, namespace,
-- and dimensions. To get the exact metric name, namespace, and dimensions,
-- inspect the
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_Metric.html Metric>
-- object that is returned by a call to
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_ListMetrics.html ListMetrics>.
metricStat_metric :: Lens.Lens' MetricStat Metric
metricStat_metric :: Lens' MetricStat Metric
metricStat_metric = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricStat' {Metric
metric :: Metric
$sel:metric:MetricStat' :: MetricStat -> Metric
metric} -> Metric
metric) (\s :: MetricStat
s@MetricStat' {} Metric
a -> MetricStat
s {$sel:metric:MetricStat' :: Metric
metric = Metric
a} :: MetricStat)

-- | The statistic to return. It can include any CloudWatch statistic or
-- extended statistic. For a list of valid values, see the table in
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_concepts.html#Statistic Statistics>
-- in the /Amazon CloudWatch User Guide/.
--
-- The most commonly used metrics for predictive scaling are @Average@ and
-- @Sum@.
metricStat_stat :: Lens.Lens' MetricStat Prelude.Text
metricStat_stat :: Lens' MetricStat Text
metricStat_stat = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricStat' {Text
stat :: Text
$sel:stat:MetricStat' :: MetricStat -> Text
stat} -> Text
stat) (\s :: MetricStat
s@MetricStat' {} Text
a -> MetricStat
s {$sel:stat:MetricStat' :: Text
stat = Text
a} :: MetricStat)

instance Data.FromXML MetricStat where
  parseXML :: [Node] -> Either String MetricStat
parseXML [Node]
x =
    Maybe Text -> Metric -> Text -> MetricStat
MetricStat'
      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
"Unit")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String a
Data..@ Text
"Metric")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String a
Data..@ Text
"Stat")

instance Prelude.Hashable MetricStat where
  hashWithSalt :: Int -> MetricStat -> Int
hashWithSalt Int
_salt MetricStat' {Maybe Text
Text
Metric
stat :: Text
metric :: Metric
unit :: Maybe Text
$sel:stat:MetricStat' :: MetricStat -> Text
$sel:metric:MetricStat' :: MetricStat -> Metric
$sel:unit:MetricStat' :: MetricStat -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
unit
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Metric
metric
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
stat

instance Prelude.NFData MetricStat where
  rnf :: MetricStat -> ()
rnf MetricStat' {Maybe Text
Text
Metric
stat :: Text
metric :: Metric
unit :: Maybe Text
$sel:stat:MetricStat' :: MetricStat -> Text
$sel:metric:MetricStat' :: MetricStat -> Metric
$sel:unit:MetricStat' :: MetricStat -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
unit
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Metric
metric
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
stat

instance Data.ToQuery MetricStat where
  toQuery :: MetricStat -> QueryString
toQuery MetricStat' {Maybe Text
Text
Metric
stat :: Text
metric :: Metric
unit :: Maybe Text
$sel:stat:MetricStat' :: MetricStat -> Text
$sel:metric:MetricStat' :: MetricStat -> Metric
$sel:unit:MetricStat' :: MetricStat -> Maybe Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Unit" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Text
unit,
        ByteString
"Metric" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Metric
metric,
        ByteString
"Stat" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Text
stat
      ]