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

import Amazonka.CloudWatch.Types.InsightRuleContributorDatapoint
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | One of the unique contributors found by a Contributor Insights rule. If
-- the rule contains multiple keys, then a unique contributor is a unique
-- combination of values from all the keys in the rule.
--
-- If the rule contains a single key, then each unique contributor is each
-- unique value for this key.
--
-- For more information, see
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_GetInsightRuleReport.html GetInsightRuleReport>.
--
-- /See:/ 'newInsightRuleContributor' smart constructor.
data InsightRuleContributor = InsightRuleContributor'
  { -- | One of the log entry field keywords that is used to define contributors
    -- for this rule.
    InsightRuleContributor -> [Text]
keys :: [Prelude.Text],
    -- | An approximation of the aggregate value that comes from this
    -- contributor.
    InsightRuleContributor -> Double
approximateAggregateValue :: Prelude.Double,
    -- | An array of the data points where this contributor is present. Only the
    -- data points when this contributor appeared are included in the array.
    InsightRuleContributor -> [InsightRuleContributorDatapoint]
datapoints :: [InsightRuleContributorDatapoint]
  }
  deriving (InsightRuleContributor -> InsightRuleContributor -> Bool
(InsightRuleContributor -> InsightRuleContributor -> Bool)
-> (InsightRuleContributor -> InsightRuleContributor -> Bool)
-> Eq InsightRuleContributor
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: InsightRuleContributor -> InsightRuleContributor -> Bool
$c/= :: InsightRuleContributor -> InsightRuleContributor -> Bool
== :: InsightRuleContributor -> InsightRuleContributor -> Bool
$c== :: InsightRuleContributor -> InsightRuleContributor -> Bool
Prelude.Eq, ReadPrec [InsightRuleContributor]
ReadPrec InsightRuleContributor
Int -> ReadS InsightRuleContributor
ReadS [InsightRuleContributor]
(Int -> ReadS InsightRuleContributor)
-> ReadS [InsightRuleContributor]
-> ReadPrec InsightRuleContributor
-> ReadPrec [InsightRuleContributor]
-> Read InsightRuleContributor
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [InsightRuleContributor]
$creadListPrec :: ReadPrec [InsightRuleContributor]
readPrec :: ReadPrec InsightRuleContributor
$creadPrec :: ReadPrec InsightRuleContributor
readList :: ReadS [InsightRuleContributor]
$creadList :: ReadS [InsightRuleContributor]
readsPrec :: Int -> ReadS InsightRuleContributor
$creadsPrec :: Int -> ReadS InsightRuleContributor
Prelude.Read, Int -> InsightRuleContributor -> ShowS
[InsightRuleContributor] -> ShowS
InsightRuleContributor -> String
(Int -> InsightRuleContributor -> ShowS)
-> (InsightRuleContributor -> String)
-> ([InsightRuleContributor] -> ShowS)
-> Show InsightRuleContributor
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InsightRuleContributor] -> ShowS
$cshowList :: [InsightRuleContributor] -> ShowS
show :: InsightRuleContributor -> String
$cshow :: InsightRuleContributor -> String
showsPrec :: Int -> InsightRuleContributor -> ShowS
$cshowsPrec :: Int -> InsightRuleContributor -> ShowS
Prelude.Show, (forall x. InsightRuleContributor -> Rep InsightRuleContributor x)
-> (forall x.
    Rep InsightRuleContributor x -> InsightRuleContributor)
-> Generic InsightRuleContributor
forall x. Rep InsightRuleContributor x -> InsightRuleContributor
forall x. InsightRuleContributor -> Rep InsightRuleContributor x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep InsightRuleContributor x -> InsightRuleContributor
$cfrom :: forall x. InsightRuleContributor -> Rep InsightRuleContributor x
Prelude.Generic)

-- |
-- Create a value of 'InsightRuleContributor' 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:
--
-- 'keys', 'insightRuleContributor_keys' - One of the log entry field keywords that is used to define contributors
-- for this rule.
--
-- 'approximateAggregateValue', 'insightRuleContributor_approximateAggregateValue' - An approximation of the aggregate value that comes from this
-- contributor.
--
-- 'datapoints', 'insightRuleContributor_datapoints' - An array of the data points where this contributor is present. Only the
-- data points when this contributor appeared are included in the array.
newInsightRuleContributor ::
  -- | 'approximateAggregateValue'
  Prelude.Double ->
  InsightRuleContributor
newInsightRuleContributor :: Double -> InsightRuleContributor
newInsightRuleContributor Double
pApproximateAggregateValue_ =
  InsightRuleContributor' :: [Text]
-> Double
-> [InsightRuleContributorDatapoint]
-> InsightRuleContributor
InsightRuleContributor'
    { $sel:keys:InsightRuleContributor' :: [Text]
keys = [Text]
forall a. Monoid a => a
Prelude.mempty,
      $sel:approximateAggregateValue:InsightRuleContributor' :: Double
approximateAggregateValue =
        Double
pApproximateAggregateValue_,
      $sel:datapoints:InsightRuleContributor' :: [InsightRuleContributorDatapoint]
datapoints = [InsightRuleContributorDatapoint]
forall a. Monoid a => a
Prelude.mempty
    }

-- | One of the log entry field keywords that is used to define contributors
-- for this rule.
insightRuleContributor_keys :: Lens.Lens' InsightRuleContributor [Prelude.Text]
insightRuleContributor_keys :: ([Text] -> f [Text])
-> InsightRuleContributor -> f InsightRuleContributor
insightRuleContributor_keys = (InsightRuleContributor -> [Text])
-> (InsightRuleContributor -> [Text] -> InsightRuleContributor)
-> Lens InsightRuleContributor InsightRuleContributor [Text] [Text]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InsightRuleContributor' {[Text]
keys :: [Text]
$sel:keys:InsightRuleContributor' :: InsightRuleContributor -> [Text]
keys} -> [Text]
keys) (\s :: InsightRuleContributor
s@InsightRuleContributor' {} [Text]
a -> InsightRuleContributor
s {$sel:keys:InsightRuleContributor' :: [Text]
keys = [Text]
a} :: InsightRuleContributor) (([Text] -> f [Text])
 -> InsightRuleContributor -> f InsightRuleContributor)
-> (([Text] -> f [Text]) -> [Text] -> f [Text])
-> ([Text] -> f [Text])
-> InsightRuleContributor
-> f InsightRuleContributor
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Text] -> f [Text]) -> [Text] -> f [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | An approximation of the aggregate value that comes from this
-- contributor.
insightRuleContributor_approximateAggregateValue :: Lens.Lens' InsightRuleContributor Prelude.Double
insightRuleContributor_approximateAggregateValue :: (Double -> f Double)
-> InsightRuleContributor -> f InsightRuleContributor
insightRuleContributor_approximateAggregateValue = (InsightRuleContributor -> Double)
-> (InsightRuleContributor -> Double -> InsightRuleContributor)
-> Lens InsightRuleContributor InsightRuleContributor Double Double
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InsightRuleContributor' {Double
approximateAggregateValue :: Double
$sel:approximateAggregateValue:InsightRuleContributor' :: InsightRuleContributor -> Double
approximateAggregateValue} -> Double
approximateAggregateValue) (\s :: InsightRuleContributor
s@InsightRuleContributor' {} Double
a -> InsightRuleContributor
s {$sel:approximateAggregateValue:InsightRuleContributor' :: Double
approximateAggregateValue = Double
a} :: InsightRuleContributor)

-- | An array of the data points where this contributor is present. Only the
-- data points when this contributor appeared are included in the array.
insightRuleContributor_datapoints :: Lens.Lens' InsightRuleContributor [InsightRuleContributorDatapoint]
insightRuleContributor_datapoints :: ([InsightRuleContributorDatapoint]
 -> f [InsightRuleContributorDatapoint])
-> InsightRuleContributor -> f InsightRuleContributor
insightRuleContributor_datapoints = (InsightRuleContributor -> [InsightRuleContributorDatapoint])
-> (InsightRuleContributor
    -> [InsightRuleContributorDatapoint] -> InsightRuleContributor)
-> Lens
     InsightRuleContributor
     InsightRuleContributor
     [InsightRuleContributorDatapoint]
     [InsightRuleContributorDatapoint]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InsightRuleContributor' {[InsightRuleContributorDatapoint]
datapoints :: [InsightRuleContributorDatapoint]
$sel:datapoints:InsightRuleContributor' :: InsightRuleContributor -> [InsightRuleContributorDatapoint]
datapoints} -> [InsightRuleContributorDatapoint]
datapoints) (\s :: InsightRuleContributor
s@InsightRuleContributor' {} [InsightRuleContributorDatapoint]
a -> InsightRuleContributor
s {$sel:datapoints:InsightRuleContributor' :: [InsightRuleContributorDatapoint]
datapoints = [InsightRuleContributorDatapoint]
a} :: InsightRuleContributor) (([InsightRuleContributorDatapoint]
  -> f [InsightRuleContributorDatapoint])
 -> InsightRuleContributor -> f InsightRuleContributor)
-> (([InsightRuleContributorDatapoint]
     -> f [InsightRuleContributorDatapoint])
    -> [InsightRuleContributorDatapoint]
    -> f [InsightRuleContributorDatapoint])
-> ([InsightRuleContributorDatapoint]
    -> f [InsightRuleContributorDatapoint])
-> InsightRuleContributor
-> f InsightRuleContributor
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([InsightRuleContributorDatapoint]
 -> f [InsightRuleContributorDatapoint])
-> [InsightRuleContributorDatapoint]
-> f [InsightRuleContributorDatapoint]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromXML InsightRuleContributor where
  parseXML :: [Node] -> Either String InsightRuleContributor
parseXML [Node]
x =
    [Text]
-> Double
-> [InsightRuleContributorDatapoint]
-> InsightRuleContributor
InsightRuleContributor'
      ([Text]
 -> Double
 -> [InsightRuleContributorDatapoint]
 -> InsightRuleContributor)
-> Either String [Text]
-> Either
     String
     (Double
      -> [InsightRuleContributorDatapoint] -> InsightRuleContributor)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( [Node]
x [Node] -> Text -> Either String (Maybe [Node])
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Keys" Either String (Maybe [Node]) -> [Node] -> Either String [Node]
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ [Node]
forall a. Monoid a => a
Prelude.mempty
                      Either String [Node]
-> ([Node] -> Either String [Text]) -> Either String [Text]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= Text -> [Node] -> Either String [Text]
forall a. FromXML a => Text -> [Node] -> Either String [a]
Core.parseXMLList Text
"member"
                  )
      Either
  String
  (Double
   -> [InsightRuleContributorDatapoint] -> InsightRuleContributor)
-> Either String Double
-> Either
     String
     ([InsightRuleContributorDatapoint] -> InsightRuleContributor)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Double
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"ApproximateAggregateValue")
      Either
  String
  ([InsightRuleContributorDatapoint] -> InsightRuleContributor)
-> Either String [InsightRuleContributorDatapoint]
-> Either String InsightRuleContributor
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( [Node]
x [Node] -> Text -> Either String (Maybe [Node])
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Datapoints" Either String (Maybe [Node]) -> [Node] -> Either String [Node]
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ [Node]
forall a. Monoid a => a
Prelude.mempty
                      Either String [Node]
-> ([Node] -> Either String [InsightRuleContributorDatapoint])
-> Either String [InsightRuleContributorDatapoint]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= Text -> [Node] -> Either String [InsightRuleContributorDatapoint]
forall a. FromXML a => Text -> [Node] -> Either String [a]
Core.parseXMLList Text
"member"
                  )

instance Prelude.Hashable InsightRuleContributor

instance Prelude.NFData InsightRuleContributor