{-# 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.MetricMathAnomalyDetector
-- 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.MetricMathAnomalyDetector where

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

-- | Indicates the CloudWatch math expression that provides the time series
-- the anomaly detector uses as input. The designated math expression must
-- return a single time series.
--
-- /See:/ 'newMetricMathAnomalyDetector' smart constructor.
data MetricMathAnomalyDetector = MetricMathAnomalyDetector'
  { -- | An array of metric data query structures that enables you to create an
    -- anomaly detector based on the result of a metric math expression. Each
    -- item in @MetricDataQueries@ gets a metric or performs a math expression.
    -- One item in @MetricDataQueries@ is the expression that provides the time
    -- series that the anomaly detector uses as input. Designate the expression
    -- by setting @ReturnData@ to @true@ for this object in the array. For all
    -- other expressions and metrics, set @ReturnData@ to @false@. The
    -- designated expression must return a single time series.
    MetricMathAnomalyDetector -> Maybe [MetricDataQuery]
metricDataQueries :: Prelude.Maybe [MetricDataQuery]
  }
  deriving (MetricMathAnomalyDetector -> MetricMathAnomalyDetector -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MetricMathAnomalyDetector -> MetricMathAnomalyDetector -> Bool
$c/= :: MetricMathAnomalyDetector -> MetricMathAnomalyDetector -> Bool
== :: MetricMathAnomalyDetector -> MetricMathAnomalyDetector -> Bool
$c== :: MetricMathAnomalyDetector -> MetricMathAnomalyDetector -> Bool
Prelude.Eq, ReadPrec [MetricMathAnomalyDetector]
ReadPrec MetricMathAnomalyDetector
Int -> ReadS MetricMathAnomalyDetector
ReadS [MetricMathAnomalyDetector]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MetricMathAnomalyDetector]
$creadListPrec :: ReadPrec [MetricMathAnomalyDetector]
readPrec :: ReadPrec MetricMathAnomalyDetector
$creadPrec :: ReadPrec MetricMathAnomalyDetector
readList :: ReadS [MetricMathAnomalyDetector]
$creadList :: ReadS [MetricMathAnomalyDetector]
readsPrec :: Int -> ReadS MetricMathAnomalyDetector
$creadsPrec :: Int -> ReadS MetricMathAnomalyDetector
Prelude.Read, Int -> MetricMathAnomalyDetector -> ShowS
[MetricMathAnomalyDetector] -> ShowS
MetricMathAnomalyDetector -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MetricMathAnomalyDetector] -> ShowS
$cshowList :: [MetricMathAnomalyDetector] -> ShowS
show :: MetricMathAnomalyDetector -> String
$cshow :: MetricMathAnomalyDetector -> String
showsPrec :: Int -> MetricMathAnomalyDetector -> ShowS
$cshowsPrec :: Int -> MetricMathAnomalyDetector -> ShowS
Prelude.Show, forall x.
Rep MetricMathAnomalyDetector x -> MetricMathAnomalyDetector
forall x.
MetricMathAnomalyDetector -> Rep MetricMathAnomalyDetector x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep MetricMathAnomalyDetector x -> MetricMathAnomalyDetector
$cfrom :: forall x.
MetricMathAnomalyDetector -> Rep MetricMathAnomalyDetector x
Prelude.Generic)

-- |
-- Create a value of 'MetricMathAnomalyDetector' 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:
--
-- 'metricDataQueries', 'metricMathAnomalyDetector_metricDataQueries' - An array of metric data query structures that enables you to create an
-- anomaly detector based on the result of a metric math expression. Each
-- item in @MetricDataQueries@ gets a metric or performs a math expression.
-- One item in @MetricDataQueries@ is the expression that provides the time
-- series that the anomaly detector uses as input. Designate the expression
-- by setting @ReturnData@ to @true@ for this object in the array. For all
-- other expressions and metrics, set @ReturnData@ to @false@. The
-- designated expression must return a single time series.
newMetricMathAnomalyDetector ::
  MetricMathAnomalyDetector
newMetricMathAnomalyDetector :: MetricMathAnomalyDetector
newMetricMathAnomalyDetector =
  MetricMathAnomalyDetector'
    { $sel:metricDataQueries:MetricMathAnomalyDetector' :: Maybe [MetricDataQuery]
metricDataQueries =
        forall a. Maybe a
Prelude.Nothing
    }

-- | An array of metric data query structures that enables you to create an
-- anomaly detector based on the result of a metric math expression. Each
-- item in @MetricDataQueries@ gets a metric or performs a math expression.
-- One item in @MetricDataQueries@ is the expression that provides the time
-- series that the anomaly detector uses as input. Designate the expression
-- by setting @ReturnData@ to @true@ for this object in the array. For all
-- other expressions and metrics, set @ReturnData@ to @false@. The
-- designated expression must return a single time series.
metricMathAnomalyDetector_metricDataQueries :: Lens.Lens' MetricMathAnomalyDetector (Prelude.Maybe [MetricDataQuery])
metricMathAnomalyDetector_metricDataQueries :: Lens' MetricMathAnomalyDetector (Maybe [MetricDataQuery])
metricMathAnomalyDetector_metricDataQueries = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricMathAnomalyDetector' {Maybe [MetricDataQuery]
metricDataQueries :: Maybe [MetricDataQuery]
$sel:metricDataQueries:MetricMathAnomalyDetector' :: MetricMathAnomalyDetector -> Maybe [MetricDataQuery]
metricDataQueries} -> Maybe [MetricDataQuery]
metricDataQueries) (\s :: MetricMathAnomalyDetector
s@MetricMathAnomalyDetector' {} Maybe [MetricDataQuery]
a -> MetricMathAnomalyDetector
s {$sel:metricDataQueries:MetricMathAnomalyDetector' :: Maybe [MetricDataQuery]
metricDataQueries = Maybe [MetricDataQuery]
a} :: MetricMathAnomalyDetector) 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 MetricMathAnomalyDetector where
  parseXML :: [Node] -> Either String MetricMathAnomalyDetector
parseXML [Node]
x =
    Maybe [MetricDataQuery] -> MetricMathAnomalyDetector
MetricMathAnomalyDetector'
      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
"MetricDataQueries"
                      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")
                  )

instance Prelude.Hashable MetricMathAnomalyDetector where
  hashWithSalt :: Int -> MetricMathAnomalyDetector -> Int
hashWithSalt Int
_salt MetricMathAnomalyDetector' {Maybe [MetricDataQuery]
metricDataQueries :: Maybe [MetricDataQuery]
$sel:metricDataQueries:MetricMathAnomalyDetector' :: MetricMathAnomalyDetector -> Maybe [MetricDataQuery]
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [MetricDataQuery]
metricDataQueries

instance Prelude.NFData MetricMathAnomalyDetector where
  rnf :: MetricMathAnomalyDetector -> ()
rnf MetricMathAnomalyDetector' {Maybe [MetricDataQuery]
metricDataQueries :: Maybe [MetricDataQuery]
$sel:metricDataQueries:MetricMathAnomalyDetector' :: MetricMathAnomalyDetector -> Maybe [MetricDataQuery]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [MetricDataQuery]
metricDataQueries

instance Data.ToQuery MetricMathAnomalyDetector where
  toQuery :: MetricMathAnomalyDetector -> QueryString
toQuery MetricMathAnomalyDetector' {Maybe [MetricDataQuery]
metricDataQueries :: Maybe [MetricDataQuery]
$sel:metricDataQueries:MetricMathAnomalyDetector' :: MetricMathAnomalyDetector -> Maybe [MetricDataQuery]
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"MetricDataQueries"
          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 [MetricDataQuery]
metricDataQueries
            )
      ]