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

import Amazonka.CloudWatch.Types.Dimension
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

-- | Designates the CloudWatch metric and statistic that provides the time
-- series the anomaly detector uses as input.
--
-- /See:/ 'newSingleMetricAnomalyDetector' smart constructor.
data SingleMetricAnomalyDetector = SingleMetricAnomalyDetector'
  { -- | The metric dimensions to create the anomaly detection model for.
    SingleMetricAnomalyDetector -> Maybe [Dimension]
dimensions :: Prelude.Maybe [Dimension],
    -- | The name of the metric to create the anomaly detection model for.
    SingleMetricAnomalyDetector -> Maybe Text
metricName :: Prelude.Maybe Prelude.Text,
    -- | The namespace of the metric to create the anomaly detection model for.
    SingleMetricAnomalyDetector -> Maybe Text
namespace :: Prelude.Maybe Prelude.Text,
    -- | The statistic to use for the metric and anomaly detection model.
    SingleMetricAnomalyDetector -> Maybe Text
stat :: Prelude.Maybe Prelude.Text
  }
  deriving (SingleMetricAnomalyDetector -> SingleMetricAnomalyDetector -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SingleMetricAnomalyDetector -> SingleMetricAnomalyDetector -> Bool
$c/= :: SingleMetricAnomalyDetector -> SingleMetricAnomalyDetector -> Bool
== :: SingleMetricAnomalyDetector -> SingleMetricAnomalyDetector -> Bool
$c== :: SingleMetricAnomalyDetector -> SingleMetricAnomalyDetector -> Bool
Prelude.Eq, ReadPrec [SingleMetricAnomalyDetector]
ReadPrec SingleMetricAnomalyDetector
Int -> ReadS SingleMetricAnomalyDetector
ReadS [SingleMetricAnomalyDetector]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SingleMetricAnomalyDetector]
$creadListPrec :: ReadPrec [SingleMetricAnomalyDetector]
readPrec :: ReadPrec SingleMetricAnomalyDetector
$creadPrec :: ReadPrec SingleMetricAnomalyDetector
readList :: ReadS [SingleMetricAnomalyDetector]
$creadList :: ReadS [SingleMetricAnomalyDetector]
readsPrec :: Int -> ReadS SingleMetricAnomalyDetector
$creadsPrec :: Int -> ReadS SingleMetricAnomalyDetector
Prelude.Read, Int -> SingleMetricAnomalyDetector -> ShowS
[SingleMetricAnomalyDetector] -> ShowS
SingleMetricAnomalyDetector -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SingleMetricAnomalyDetector] -> ShowS
$cshowList :: [SingleMetricAnomalyDetector] -> ShowS
show :: SingleMetricAnomalyDetector -> String
$cshow :: SingleMetricAnomalyDetector -> String
showsPrec :: Int -> SingleMetricAnomalyDetector -> ShowS
$cshowsPrec :: Int -> SingleMetricAnomalyDetector -> ShowS
Prelude.Show, forall x.
Rep SingleMetricAnomalyDetector x -> SingleMetricAnomalyDetector
forall x.
SingleMetricAnomalyDetector -> Rep SingleMetricAnomalyDetector x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep SingleMetricAnomalyDetector x -> SingleMetricAnomalyDetector
$cfrom :: forall x.
SingleMetricAnomalyDetector -> Rep SingleMetricAnomalyDetector x
Prelude.Generic)

-- |
-- Create a value of 'SingleMetricAnomalyDetector' 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:
--
-- 'dimensions', 'singleMetricAnomalyDetector_dimensions' - The metric dimensions to create the anomaly detection model for.
--
-- 'metricName', 'singleMetricAnomalyDetector_metricName' - The name of the metric to create the anomaly detection model for.
--
-- 'namespace', 'singleMetricAnomalyDetector_namespace' - The namespace of the metric to create the anomaly detection model for.
--
-- 'stat', 'singleMetricAnomalyDetector_stat' - The statistic to use for the metric and anomaly detection model.
newSingleMetricAnomalyDetector ::
  SingleMetricAnomalyDetector
newSingleMetricAnomalyDetector :: SingleMetricAnomalyDetector
newSingleMetricAnomalyDetector =
  SingleMetricAnomalyDetector'
    { $sel:dimensions:SingleMetricAnomalyDetector' :: Maybe [Dimension]
dimensions =
        forall a. Maybe a
Prelude.Nothing,
      $sel:metricName:SingleMetricAnomalyDetector' :: Maybe Text
metricName = forall a. Maybe a
Prelude.Nothing,
      $sel:namespace:SingleMetricAnomalyDetector' :: Maybe Text
namespace = forall a. Maybe a
Prelude.Nothing,
      $sel:stat:SingleMetricAnomalyDetector' :: Maybe Text
stat = forall a. Maybe a
Prelude.Nothing
    }

-- | The metric dimensions to create the anomaly detection model for.
singleMetricAnomalyDetector_dimensions :: Lens.Lens' SingleMetricAnomalyDetector (Prelude.Maybe [Dimension])
singleMetricAnomalyDetector_dimensions :: Lens' SingleMetricAnomalyDetector (Maybe [Dimension])
singleMetricAnomalyDetector_dimensions = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SingleMetricAnomalyDetector' {Maybe [Dimension]
dimensions :: Maybe [Dimension]
$sel:dimensions:SingleMetricAnomalyDetector' :: SingleMetricAnomalyDetector -> Maybe [Dimension]
dimensions} -> Maybe [Dimension]
dimensions) (\s :: SingleMetricAnomalyDetector
s@SingleMetricAnomalyDetector' {} Maybe [Dimension]
a -> SingleMetricAnomalyDetector
s {$sel:dimensions:SingleMetricAnomalyDetector' :: Maybe [Dimension]
dimensions = Maybe [Dimension]
a} :: SingleMetricAnomalyDetector) 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

-- | The name of the metric to create the anomaly detection model for.
singleMetricAnomalyDetector_metricName :: Lens.Lens' SingleMetricAnomalyDetector (Prelude.Maybe Prelude.Text)
singleMetricAnomalyDetector_metricName :: Lens' SingleMetricAnomalyDetector (Maybe Text)
singleMetricAnomalyDetector_metricName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SingleMetricAnomalyDetector' {Maybe Text
metricName :: Maybe Text
$sel:metricName:SingleMetricAnomalyDetector' :: SingleMetricAnomalyDetector -> Maybe Text
metricName} -> Maybe Text
metricName) (\s :: SingleMetricAnomalyDetector
s@SingleMetricAnomalyDetector' {} Maybe Text
a -> SingleMetricAnomalyDetector
s {$sel:metricName:SingleMetricAnomalyDetector' :: Maybe Text
metricName = Maybe Text
a} :: SingleMetricAnomalyDetector)

-- | The namespace of the metric to create the anomaly detection model for.
singleMetricAnomalyDetector_namespace :: Lens.Lens' SingleMetricAnomalyDetector (Prelude.Maybe Prelude.Text)
singleMetricAnomalyDetector_namespace :: Lens' SingleMetricAnomalyDetector (Maybe Text)
singleMetricAnomalyDetector_namespace = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SingleMetricAnomalyDetector' {Maybe Text
namespace :: Maybe Text
$sel:namespace:SingleMetricAnomalyDetector' :: SingleMetricAnomalyDetector -> Maybe Text
namespace} -> Maybe Text
namespace) (\s :: SingleMetricAnomalyDetector
s@SingleMetricAnomalyDetector' {} Maybe Text
a -> SingleMetricAnomalyDetector
s {$sel:namespace:SingleMetricAnomalyDetector' :: Maybe Text
namespace = Maybe Text
a} :: SingleMetricAnomalyDetector)

-- | The statistic to use for the metric and anomaly detection model.
singleMetricAnomalyDetector_stat :: Lens.Lens' SingleMetricAnomalyDetector (Prelude.Maybe Prelude.Text)
singleMetricAnomalyDetector_stat :: Lens' SingleMetricAnomalyDetector (Maybe Text)
singleMetricAnomalyDetector_stat = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SingleMetricAnomalyDetector' {Maybe Text
stat :: Maybe Text
$sel:stat:SingleMetricAnomalyDetector' :: SingleMetricAnomalyDetector -> Maybe Text
stat} -> Maybe Text
stat) (\s :: SingleMetricAnomalyDetector
s@SingleMetricAnomalyDetector' {} Maybe Text
a -> SingleMetricAnomalyDetector
s {$sel:stat:SingleMetricAnomalyDetector' :: Maybe Text
stat = Maybe Text
a} :: SingleMetricAnomalyDetector)

instance Data.FromXML SingleMetricAnomalyDetector where
  parseXML :: [Node] -> Either String SingleMetricAnomalyDetector
parseXML [Node]
x =
    Maybe [Dimension]
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> SingleMetricAnomalyDetector
SingleMetricAnomalyDetector'
      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
"Dimensions"
                      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
"member")
                  )
      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
"MetricName")
      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
"Namespace")
      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
"Stat")

instance Prelude.Hashable SingleMetricAnomalyDetector where
  hashWithSalt :: Int -> SingleMetricAnomalyDetector -> Int
hashWithSalt Int
_salt SingleMetricAnomalyDetector' {Maybe [Dimension]
Maybe Text
stat :: Maybe Text
namespace :: Maybe Text
metricName :: Maybe Text
dimensions :: Maybe [Dimension]
$sel:stat:SingleMetricAnomalyDetector' :: SingleMetricAnomalyDetector -> Maybe Text
$sel:namespace:SingleMetricAnomalyDetector' :: SingleMetricAnomalyDetector -> Maybe Text
$sel:metricName:SingleMetricAnomalyDetector' :: SingleMetricAnomalyDetector -> Maybe Text
$sel:dimensions:SingleMetricAnomalyDetector' :: SingleMetricAnomalyDetector -> Maybe [Dimension]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Dimension]
dimensions
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
metricName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
namespace
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
stat

instance Prelude.NFData SingleMetricAnomalyDetector where
  rnf :: SingleMetricAnomalyDetector -> ()
rnf SingleMetricAnomalyDetector' {Maybe [Dimension]
Maybe Text
stat :: Maybe Text
namespace :: Maybe Text
metricName :: Maybe Text
dimensions :: Maybe [Dimension]
$sel:stat:SingleMetricAnomalyDetector' :: SingleMetricAnomalyDetector -> Maybe Text
$sel:namespace:SingleMetricAnomalyDetector' :: SingleMetricAnomalyDetector -> Maybe Text
$sel:metricName:SingleMetricAnomalyDetector' :: SingleMetricAnomalyDetector -> Maybe Text
$sel:dimensions:SingleMetricAnomalyDetector' :: SingleMetricAnomalyDetector -> Maybe [Dimension]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Dimension]
dimensions
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
metricName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
namespace
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
stat

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