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

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

-- | The configuration specifies details about how the anomaly detection
-- model is to be trained, including time ranges to exclude from use for
-- training the model and the time zone to use for the metric.
--
-- /See:/ 'newAnomalyDetectorConfiguration' smart constructor.
data AnomalyDetectorConfiguration = AnomalyDetectorConfiguration'
  { -- | An array of time ranges to exclude from use when the anomaly detection
    -- model is trained. Use this to make sure that events that could cause
    -- unusual values for the metric, such as deployments, aren\'t used when
    -- CloudWatch creates the model.
    AnomalyDetectorConfiguration -> Maybe [Range]
excludedTimeRanges :: Prelude.Maybe [Range],
    -- | The time zone to use for the metric. This is useful to enable the model
    -- to automatically account for daylight savings time changes if the metric
    -- is sensitive to such time changes.
    --
    -- To specify a time zone, use the name of the time zone as specified in
    -- the standard tz database. For more information, see
    -- <https://en.wikipedia.org/wiki/Tz_database tz database>.
    AnomalyDetectorConfiguration -> Maybe Text
metricTimezone :: Prelude.Maybe Prelude.Text
  }
  deriving (AnomalyDetectorConfiguration
-> AnomalyDetectorConfiguration -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AnomalyDetectorConfiguration
-> AnomalyDetectorConfiguration -> Bool
$c/= :: AnomalyDetectorConfiguration
-> AnomalyDetectorConfiguration -> Bool
== :: AnomalyDetectorConfiguration
-> AnomalyDetectorConfiguration -> Bool
$c== :: AnomalyDetectorConfiguration
-> AnomalyDetectorConfiguration -> Bool
Prelude.Eq, ReadPrec [AnomalyDetectorConfiguration]
ReadPrec AnomalyDetectorConfiguration
Int -> ReadS AnomalyDetectorConfiguration
ReadS [AnomalyDetectorConfiguration]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AnomalyDetectorConfiguration]
$creadListPrec :: ReadPrec [AnomalyDetectorConfiguration]
readPrec :: ReadPrec AnomalyDetectorConfiguration
$creadPrec :: ReadPrec AnomalyDetectorConfiguration
readList :: ReadS [AnomalyDetectorConfiguration]
$creadList :: ReadS [AnomalyDetectorConfiguration]
readsPrec :: Int -> ReadS AnomalyDetectorConfiguration
$creadsPrec :: Int -> ReadS AnomalyDetectorConfiguration
Prelude.Read, Int -> AnomalyDetectorConfiguration -> ShowS
[AnomalyDetectorConfiguration] -> ShowS
AnomalyDetectorConfiguration -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AnomalyDetectorConfiguration] -> ShowS
$cshowList :: [AnomalyDetectorConfiguration] -> ShowS
show :: AnomalyDetectorConfiguration -> String
$cshow :: AnomalyDetectorConfiguration -> String
showsPrec :: Int -> AnomalyDetectorConfiguration -> ShowS
$cshowsPrec :: Int -> AnomalyDetectorConfiguration -> ShowS
Prelude.Show, forall x.
Rep AnomalyDetectorConfiguration x -> AnomalyDetectorConfiguration
forall x.
AnomalyDetectorConfiguration -> Rep AnomalyDetectorConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep AnomalyDetectorConfiguration x -> AnomalyDetectorConfiguration
$cfrom :: forall x.
AnomalyDetectorConfiguration -> Rep AnomalyDetectorConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'AnomalyDetectorConfiguration' 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:
--
-- 'excludedTimeRanges', 'anomalyDetectorConfiguration_excludedTimeRanges' - An array of time ranges to exclude from use when the anomaly detection
-- model is trained. Use this to make sure that events that could cause
-- unusual values for the metric, such as deployments, aren\'t used when
-- CloudWatch creates the model.
--
-- 'metricTimezone', 'anomalyDetectorConfiguration_metricTimezone' - The time zone to use for the metric. This is useful to enable the model
-- to automatically account for daylight savings time changes if the metric
-- is sensitive to such time changes.
--
-- To specify a time zone, use the name of the time zone as specified in
-- the standard tz database. For more information, see
-- <https://en.wikipedia.org/wiki/Tz_database tz database>.
newAnomalyDetectorConfiguration ::
  AnomalyDetectorConfiguration
newAnomalyDetectorConfiguration :: AnomalyDetectorConfiguration
newAnomalyDetectorConfiguration =
  AnomalyDetectorConfiguration'
    { $sel:excludedTimeRanges:AnomalyDetectorConfiguration' :: Maybe [Range]
excludedTimeRanges =
        forall a. Maybe a
Prelude.Nothing,
      $sel:metricTimezone:AnomalyDetectorConfiguration' :: Maybe Text
metricTimezone = forall a. Maybe a
Prelude.Nothing
    }

-- | An array of time ranges to exclude from use when the anomaly detection
-- model is trained. Use this to make sure that events that could cause
-- unusual values for the metric, such as deployments, aren\'t used when
-- CloudWatch creates the model.
anomalyDetectorConfiguration_excludedTimeRanges :: Lens.Lens' AnomalyDetectorConfiguration (Prelude.Maybe [Range])
anomalyDetectorConfiguration_excludedTimeRanges :: Lens' AnomalyDetectorConfiguration (Maybe [Range])
anomalyDetectorConfiguration_excludedTimeRanges = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AnomalyDetectorConfiguration' {Maybe [Range]
excludedTimeRanges :: Maybe [Range]
$sel:excludedTimeRanges:AnomalyDetectorConfiguration' :: AnomalyDetectorConfiguration -> Maybe [Range]
excludedTimeRanges} -> Maybe [Range]
excludedTimeRanges) (\s :: AnomalyDetectorConfiguration
s@AnomalyDetectorConfiguration' {} Maybe [Range]
a -> AnomalyDetectorConfiguration
s {$sel:excludedTimeRanges:AnomalyDetectorConfiguration' :: Maybe [Range]
excludedTimeRanges = Maybe [Range]
a} :: AnomalyDetectorConfiguration) 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 time zone to use for the metric. This is useful to enable the model
-- to automatically account for daylight savings time changes if the metric
-- is sensitive to such time changes.
--
-- To specify a time zone, use the name of the time zone as specified in
-- the standard tz database. For more information, see
-- <https://en.wikipedia.org/wiki/Tz_database tz database>.
anomalyDetectorConfiguration_metricTimezone :: Lens.Lens' AnomalyDetectorConfiguration (Prelude.Maybe Prelude.Text)
anomalyDetectorConfiguration_metricTimezone :: Lens' AnomalyDetectorConfiguration (Maybe Text)
anomalyDetectorConfiguration_metricTimezone = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AnomalyDetectorConfiguration' {Maybe Text
metricTimezone :: Maybe Text
$sel:metricTimezone:AnomalyDetectorConfiguration' :: AnomalyDetectorConfiguration -> Maybe Text
metricTimezone} -> Maybe Text
metricTimezone) (\s :: AnomalyDetectorConfiguration
s@AnomalyDetectorConfiguration' {} Maybe Text
a -> AnomalyDetectorConfiguration
s {$sel:metricTimezone:AnomalyDetectorConfiguration' :: Maybe Text
metricTimezone = Maybe Text
a} :: AnomalyDetectorConfiguration)

instance Data.FromXML AnomalyDetectorConfiguration where
  parseXML :: [Node] -> Either String AnomalyDetectorConfiguration
parseXML [Node]
x =
    Maybe [Range] -> Maybe Text -> AnomalyDetectorConfiguration
AnomalyDetectorConfiguration'
      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
"ExcludedTimeRanges"
                      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
"MetricTimezone")

instance
  Prelude.Hashable
    AnomalyDetectorConfiguration
  where
  hashWithSalt :: Int -> AnomalyDetectorConfiguration -> Int
hashWithSalt Int
_salt AnomalyDetectorConfiguration' {Maybe [Range]
Maybe Text
metricTimezone :: Maybe Text
excludedTimeRanges :: Maybe [Range]
$sel:metricTimezone:AnomalyDetectorConfiguration' :: AnomalyDetectorConfiguration -> Maybe Text
$sel:excludedTimeRanges:AnomalyDetectorConfiguration' :: AnomalyDetectorConfiguration -> Maybe [Range]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Range]
excludedTimeRanges
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
metricTimezone

instance Prelude.NFData AnomalyDetectorConfiguration where
  rnf :: AnomalyDetectorConfiguration -> ()
rnf AnomalyDetectorConfiguration' {Maybe [Range]
Maybe Text
metricTimezone :: Maybe Text
excludedTimeRanges :: Maybe [Range]
$sel:metricTimezone:AnomalyDetectorConfiguration' :: AnomalyDetectorConfiguration -> Maybe Text
$sel:excludedTimeRanges:AnomalyDetectorConfiguration' :: AnomalyDetectorConfiguration -> Maybe [Range]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Range]
excludedTimeRanges
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
metricTimezone

instance Data.ToQuery AnomalyDetectorConfiguration where
  toQuery :: AnomalyDetectorConfiguration -> QueryString
toQuery AnomalyDetectorConfiguration' {Maybe [Range]
Maybe Text
metricTimezone :: Maybe Text
excludedTimeRanges :: Maybe [Range]
$sel:metricTimezone:AnomalyDetectorConfiguration' :: AnomalyDetectorConfiguration -> Maybe Text
$sel:excludedTimeRanges:AnomalyDetectorConfiguration' :: AnomalyDetectorConfiguration -> Maybe [Range]
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"ExcludedTimeRanges"
          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 [Range]
excludedTimeRanges
            ),
        ByteString
"MetricTimezone" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Text
metricTimezone
      ]