{-# 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.CostExplorer.Types.Anomaly
-- 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.CostExplorer.Types.Anomaly where

import qualified Amazonka.Core as Core
import Amazonka.CostExplorer.Types.AnomalyFeedbackType
import Amazonka.CostExplorer.Types.AnomalyScore
import Amazonka.CostExplorer.Types.Impact
import Amazonka.CostExplorer.Types.RootCause
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | An unusual cost pattern. This consists of the detailed metadata and the
-- current status of the anomaly object.
--
-- /See:/ 'newAnomaly' smart constructor.
data Anomaly = Anomaly'
  { -- | The first day the anomaly is detected.
    Anomaly -> Maybe Text
anomalyStartDate :: Prelude.Maybe Prelude.Text,
    -- | The dimension for the anomaly (for example, an Amazon Web Services
    -- service in a service monitor).
    Anomaly -> Maybe Text
dimensionValue :: Prelude.Maybe Prelude.Text,
    -- | The list of identified root causes for the anomaly.
    Anomaly -> Maybe [RootCause]
rootCauses :: Prelude.Maybe [RootCause],
    -- | The last day the anomaly is detected.
    Anomaly -> Maybe Text
anomalyEndDate :: Prelude.Maybe Prelude.Text,
    -- | The feedback value.
    Anomaly -> Maybe AnomalyFeedbackType
feedback :: Prelude.Maybe AnomalyFeedbackType,
    -- | The unique identifier for the anomaly.
    Anomaly -> Text
anomalyId :: Prelude.Text,
    -- | The latest and maximum score for the anomaly.
    Anomaly -> AnomalyScore
anomalyScore :: AnomalyScore,
    -- | The dollar impact for the anomaly.
    Anomaly -> Impact
impact :: Impact,
    -- | The Amazon Resource Name (ARN) for the cost monitor that generated this
    -- anomaly.
    Anomaly -> Text
monitorArn :: Prelude.Text
  }
  deriving (Anomaly -> Anomaly -> Bool
(Anomaly -> Anomaly -> Bool)
-> (Anomaly -> Anomaly -> Bool) -> Eq Anomaly
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Anomaly -> Anomaly -> Bool
$c/= :: Anomaly -> Anomaly -> Bool
== :: Anomaly -> Anomaly -> Bool
$c== :: Anomaly -> Anomaly -> Bool
Prelude.Eq, ReadPrec [Anomaly]
ReadPrec Anomaly
Int -> ReadS Anomaly
ReadS [Anomaly]
(Int -> ReadS Anomaly)
-> ReadS [Anomaly]
-> ReadPrec Anomaly
-> ReadPrec [Anomaly]
-> Read Anomaly
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Anomaly]
$creadListPrec :: ReadPrec [Anomaly]
readPrec :: ReadPrec Anomaly
$creadPrec :: ReadPrec Anomaly
readList :: ReadS [Anomaly]
$creadList :: ReadS [Anomaly]
readsPrec :: Int -> ReadS Anomaly
$creadsPrec :: Int -> ReadS Anomaly
Prelude.Read, Int -> Anomaly -> ShowS
[Anomaly] -> ShowS
Anomaly -> String
(Int -> Anomaly -> ShowS)
-> (Anomaly -> String) -> ([Anomaly] -> ShowS) -> Show Anomaly
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Anomaly] -> ShowS
$cshowList :: [Anomaly] -> ShowS
show :: Anomaly -> String
$cshow :: Anomaly -> String
showsPrec :: Int -> Anomaly -> ShowS
$cshowsPrec :: Int -> Anomaly -> ShowS
Prelude.Show, (forall x. Anomaly -> Rep Anomaly x)
-> (forall x. Rep Anomaly x -> Anomaly) -> Generic Anomaly
forall x. Rep Anomaly x -> Anomaly
forall x. Anomaly -> Rep Anomaly x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Anomaly x -> Anomaly
$cfrom :: forall x. Anomaly -> Rep Anomaly x
Prelude.Generic)

-- |
-- Create a value of 'Anomaly' 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:
--
-- 'anomalyStartDate', 'anomaly_anomalyStartDate' - The first day the anomaly is detected.
--
-- 'dimensionValue', 'anomaly_dimensionValue' - The dimension for the anomaly (for example, an Amazon Web Services
-- service in a service monitor).
--
-- 'rootCauses', 'anomaly_rootCauses' - The list of identified root causes for the anomaly.
--
-- 'anomalyEndDate', 'anomaly_anomalyEndDate' - The last day the anomaly is detected.
--
-- 'feedback', 'anomaly_feedback' - The feedback value.
--
-- 'anomalyId', 'anomaly_anomalyId' - The unique identifier for the anomaly.
--
-- 'anomalyScore', 'anomaly_anomalyScore' - The latest and maximum score for the anomaly.
--
-- 'impact', 'anomaly_impact' - The dollar impact for the anomaly.
--
-- 'monitorArn', 'anomaly_monitorArn' - The Amazon Resource Name (ARN) for the cost monitor that generated this
-- anomaly.
newAnomaly ::
  -- | 'anomalyId'
  Prelude.Text ->
  -- | 'anomalyScore'
  AnomalyScore ->
  -- | 'impact'
  Impact ->
  -- | 'monitorArn'
  Prelude.Text ->
  Anomaly
newAnomaly :: Text -> AnomalyScore -> Impact -> Text -> Anomaly
newAnomaly
  Text
pAnomalyId_
  AnomalyScore
pAnomalyScore_
  Impact
pImpact_
  Text
pMonitorArn_ =
    Anomaly' :: Maybe Text
-> Maybe Text
-> Maybe [RootCause]
-> Maybe Text
-> Maybe AnomalyFeedbackType
-> Text
-> AnomalyScore
-> Impact
-> Text
-> Anomaly
Anomaly'
      { $sel:anomalyStartDate:Anomaly' :: Maybe Text
anomalyStartDate = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:dimensionValue:Anomaly' :: Maybe Text
dimensionValue = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:rootCauses:Anomaly' :: Maybe [RootCause]
rootCauses = Maybe [RootCause]
forall a. Maybe a
Prelude.Nothing,
        $sel:anomalyEndDate:Anomaly' :: Maybe Text
anomalyEndDate = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:feedback:Anomaly' :: Maybe AnomalyFeedbackType
feedback = Maybe AnomalyFeedbackType
forall a. Maybe a
Prelude.Nothing,
        $sel:anomalyId:Anomaly' :: Text
anomalyId = Text
pAnomalyId_,
        $sel:anomalyScore:Anomaly' :: AnomalyScore
anomalyScore = AnomalyScore
pAnomalyScore_,
        $sel:impact:Anomaly' :: Impact
impact = Impact
pImpact_,
        $sel:monitorArn:Anomaly' :: Text
monitorArn = Text
pMonitorArn_
      }

-- | The first day the anomaly is detected.
anomaly_anomalyStartDate :: Lens.Lens' Anomaly (Prelude.Maybe Prelude.Text)
anomaly_anomalyStartDate :: (Maybe Text -> f (Maybe Text)) -> Anomaly -> f Anomaly
anomaly_anomalyStartDate = (Anomaly -> Maybe Text)
-> (Anomaly -> Maybe Text -> Anomaly)
-> Lens Anomaly Anomaly (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Anomaly' {Maybe Text
anomalyStartDate :: Maybe Text
$sel:anomalyStartDate:Anomaly' :: Anomaly -> Maybe Text
anomalyStartDate} -> Maybe Text
anomalyStartDate) (\s :: Anomaly
s@Anomaly' {} Maybe Text
a -> Anomaly
s {$sel:anomalyStartDate:Anomaly' :: Maybe Text
anomalyStartDate = Maybe Text
a} :: Anomaly)

-- | The dimension for the anomaly (for example, an Amazon Web Services
-- service in a service monitor).
anomaly_dimensionValue :: Lens.Lens' Anomaly (Prelude.Maybe Prelude.Text)
anomaly_dimensionValue :: (Maybe Text -> f (Maybe Text)) -> Anomaly -> f Anomaly
anomaly_dimensionValue = (Anomaly -> Maybe Text)
-> (Anomaly -> Maybe Text -> Anomaly)
-> Lens Anomaly Anomaly (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Anomaly' {Maybe Text
dimensionValue :: Maybe Text
$sel:dimensionValue:Anomaly' :: Anomaly -> Maybe Text
dimensionValue} -> Maybe Text
dimensionValue) (\s :: Anomaly
s@Anomaly' {} Maybe Text
a -> Anomaly
s {$sel:dimensionValue:Anomaly' :: Maybe Text
dimensionValue = Maybe Text
a} :: Anomaly)

-- | The list of identified root causes for the anomaly.
anomaly_rootCauses :: Lens.Lens' Anomaly (Prelude.Maybe [RootCause])
anomaly_rootCauses :: (Maybe [RootCause] -> f (Maybe [RootCause]))
-> Anomaly -> f Anomaly
anomaly_rootCauses = (Anomaly -> Maybe [RootCause])
-> (Anomaly -> Maybe [RootCause] -> Anomaly)
-> Lens Anomaly Anomaly (Maybe [RootCause]) (Maybe [RootCause])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Anomaly' {Maybe [RootCause]
rootCauses :: Maybe [RootCause]
$sel:rootCauses:Anomaly' :: Anomaly -> Maybe [RootCause]
rootCauses} -> Maybe [RootCause]
rootCauses) (\s :: Anomaly
s@Anomaly' {} Maybe [RootCause]
a -> Anomaly
s {$sel:rootCauses:Anomaly' :: Maybe [RootCause]
rootCauses = Maybe [RootCause]
a} :: Anomaly) ((Maybe [RootCause] -> f (Maybe [RootCause]))
 -> Anomaly -> f Anomaly)
-> ((Maybe [RootCause] -> f (Maybe [RootCause]))
    -> Maybe [RootCause] -> f (Maybe [RootCause]))
-> (Maybe [RootCause] -> f (Maybe [RootCause]))
-> Anomaly
-> f Anomaly
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [RootCause] [RootCause] [RootCause] [RootCause]
-> Iso
     (Maybe [RootCause])
     (Maybe [RootCause])
     (Maybe [RootCause])
     (Maybe [RootCause])
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 [RootCause] [RootCause] [RootCause] [RootCause]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The last day the anomaly is detected.
anomaly_anomalyEndDate :: Lens.Lens' Anomaly (Prelude.Maybe Prelude.Text)
anomaly_anomalyEndDate :: (Maybe Text -> f (Maybe Text)) -> Anomaly -> f Anomaly
anomaly_anomalyEndDate = (Anomaly -> Maybe Text)
-> (Anomaly -> Maybe Text -> Anomaly)
-> Lens Anomaly Anomaly (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Anomaly' {Maybe Text
anomalyEndDate :: Maybe Text
$sel:anomalyEndDate:Anomaly' :: Anomaly -> Maybe Text
anomalyEndDate} -> Maybe Text
anomalyEndDate) (\s :: Anomaly
s@Anomaly' {} Maybe Text
a -> Anomaly
s {$sel:anomalyEndDate:Anomaly' :: Maybe Text
anomalyEndDate = Maybe Text
a} :: Anomaly)

-- | The feedback value.
anomaly_feedback :: Lens.Lens' Anomaly (Prelude.Maybe AnomalyFeedbackType)
anomaly_feedback :: (Maybe AnomalyFeedbackType -> f (Maybe AnomalyFeedbackType))
-> Anomaly -> f Anomaly
anomaly_feedback = (Anomaly -> Maybe AnomalyFeedbackType)
-> (Anomaly -> Maybe AnomalyFeedbackType -> Anomaly)
-> Lens
     Anomaly
     Anomaly
     (Maybe AnomalyFeedbackType)
     (Maybe AnomalyFeedbackType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Anomaly' {Maybe AnomalyFeedbackType
feedback :: Maybe AnomalyFeedbackType
$sel:feedback:Anomaly' :: Anomaly -> Maybe AnomalyFeedbackType
feedback} -> Maybe AnomalyFeedbackType
feedback) (\s :: Anomaly
s@Anomaly' {} Maybe AnomalyFeedbackType
a -> Anomaly
s {$sel:feedback:Anomaly' :: Maybe AnomalyFeedbackType
feedback = Maybe AnomalyFeedbackType
a} :: Anomaly)

-- | The unique identifier for the anomaly.
anomaly_anomalyId :: Lens.Lens' Anomaly Prelude.Text
anomaly_anomalyId :: (Text -> f Text) -> Anomaly -> f Anomaly
anomaly_anomalyId = (Anomaly -> Text)
-> (Anomaly -> Text -> Anomaly) -> Lens Anomaly Anomaly Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Anomaly' {Text
anomalyId :: Text
$sel:anomalyId:Anomaly' :: Anomaly -> Text
anomalyId} -> Text
anomalyId) (\s :: Anomaly
s@Anomaly' {} Text
a -> Anomaly
s {$sel:anomalyId:Anomaly' :: Text
anomalyId = Text
a} :: Anomaly)

-- | The latest and maximum score for the anomaly.
anomaly_anomalyScore :: Lens.Lens' Anomaly AnomalyScore
anomaly_anomalyScore :: (AnomalyScore -> f AnomalyScore) -> Anomaly -> f Anomaly
anomaly_anomalyScore = (Anomaly -> AnomalyScore)
-> (Anomaly -> AnomalyScore -> Anomaly)
-> Lens Anomaly Anomaly AnomalyScore AnomalyScore
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Anomaly' {AnomalyScore
anomalyScore :: AnomalyScore
$sel:anomalyScore:Anomaly' :: Anomaly -> AnomalyScore
anomalyScore} -> AnomalyScore
anomalyScore) (\s :: Anomaly
s@Anomaly' {} AnomalyScore
a -> Anomaly
s {$sel:anomalyScore:Anomaly' :: AnomalyScore
anomalyScore = AnomalyScore
a} :: Anomaly)

-- | The dollar impact for the anomaly.
anomaly_impact :: Lens.Lens' Anomaly Impact
anomaly_impact :: (Impact -> f Impact) -> Anomaly -> f Anomaly
anomaly_impact = (Anomaly -> Impact)
-> (Anomaly -> Impact -> Anomaly)
-> Lens Anomaly Anomaly Impact Impact
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Anomaly' {Impact
impact :: Impact
$sel:impact:Anomaly' :: Anomaly -> Impact
impact} -> Impact
impact) (\s :: Anomaly
s@Anomaly' {} Impact
a -> Anomaly
s {$sel:impact:Anomaly' :: Impact
impact = Impact
a} :: Anomaly)

-- | The Amazon Resource Name (ARN) for the cost monitor that generated this
-- anomaly.
anomaly_monitorArn :: Lens.Lens' Anomaly Prelude.Text
anomaly_monitorArn :: (Text -> f Text) -> Anomaly -> f Anomaly
anomaly_monitorArn = (Anomaly -> Text)
-> (Anomaly -> Text -> Anomaly) -> Lens Anomaly Anomaly Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Anomaly' {Text
monitorArn :: Text
$sel:monitorArn:Anomaly' :: Anomaly -> Text
monitorArn} -> Text
monitorArn) (\s :: Anomaly
s@Anomaly' {} Text
a -> Anomaly
s {$sel:monitorArn:Anomaly' :: Text
monitorArn = Text
a} :: Anomaly)

instance Core.FromJSON Anomaly where
  parseJSON :: Value -> Parser Anomaly
parseJSON =
    String -> (Object -> Parser Anomaly) -> Value -> Parser Anomaly
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Anomaly"
      ( \Object
x ->
          Maybe Text
-> Maybe Text
-> Maybe [RootCause]
-> Maybe Text
-> Maybe AnomalyFeedbackType
-> Text
-> AnomalyScore
-> Impact
-> Text
-> Anomaly
Anomaly'
            (Maybe Text
 -> Maybe Text
 -> Maybe [RootCause]
 -> Maybe Text
 -> Maybe AnomalyFeedbackType
 -> Text
 -> AnomalyScore
 -> Impact
 -> Text
 -> Anomaly)
-> Parser (Maybe Text)
-> Parser
     (Maybe Text
      -> Maybe [RootCause]
      -> Maybe Text
      -> Maybe AnomalyFeedbackType
      -> Text
      -> AnomalyScore
      -> Impact
      -> Text
      -> Anomaly)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"AnomalyStartDate")
            Parser
  (Maybe Text
   -> Maybe [RootCause]
   -> Maybe Text
   -> Maybe AnomalyFeedbackType
   -> Text
   -> AnomalyScore
   -> Impact
   -> Text
   -> Anomaly)
-> Parser (Maybe Text)
-> Parser
     (Maybe [RootCause]
      -> Maybe Text
      -> Maybe AnomalyFeedbackType
      -> Text
      -> AnomalyScore
      -> Impact
      -> Text
      -> Anomaly)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"DimensionValue")
            Parser
  (Maybe [RootCause]
   -> Maybe Text
   -> Maybe AnomalyFeedbackType
   -> Text
   -> AnomalyScore
   -> Impact
   -> Text
   -> Anomaly)
-> Parser (Maybe [RootCause])
-> Parser
     (Maybe Text
      -> Maybe AnomalyFeedbackType
      -> Text
      -> AnomalyScore
      -> Impact
      -> Text
      -> Anomaly)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Maybe [RootCause]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"RootCauses" Parser (Maybe (Maybe [RootCause]))
-> Maybe [RootCause] -> Parser (Maybe [RootCause])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [RootCause]
forall a. Monoid a => a
Prelude.mempty)
            Parser
  (Maybe Text
   -> Maybe AnomalyFeedbackType
   -> Text
   -> AnomalyScore
   -> Impact
   -> Text
   -> Anomaly)
-> Parser (Maybe Text)
-> Parser
     (Maybe AnomalyFeedbackType
      -> Text -> AnomalyScore -> Impact -> Text -> Anomaly)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"AnomalyEndDate")
            Parser
  (Maybe AnomalyFeedbackType
   -> Text -> AnomalyScore -> Impact -> Text -> Anomaly)
-> Parser (Maybe AnomalyFeedbackType)
-> Parser (Text -> AnomalyScore -> Impact -> Text -> Anomaly)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe AnomalyFeedbackType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Feedback")
            Parser (Text -> AnomalyScore -> Impact -> Text -> Anomaly)
-> Parser Text
-> Parser (AnomalyScore -> Impact -> Text -> Anomaly)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"AnomalyId")
            Parser (AnomalyScore -> Impact -> Text -> Anomaly)
-> Parser AnomalyScore -> Parser (Impact -> Text -> Anomaly)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser AnomalyScore
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"AnomalyScore")
            Parser (Impact -> Text -> Anomaly)
-> Parser Impact -> Parser (Text -> Anomaly)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Impact
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Impact")
            Parser (Text -> Anomaly) -> Parser Text -> Parser Anomaly
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"MonitorArn")
      )

instance Prelude.Hashable Anomaly

instance Prelude.NFData Anomaly