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

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

-- | 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
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]
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
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. 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'
    { $sel:keys:InsightRuleContributor' :: [Text]
keys = forall a. Monoid a => a
Prelude.mempty,
      $sel:approximateAggregateValue:InsightRuleContributor' :: Double
approximateAggregateValue =
        Double
pApproximateAggregateValue_,
      $sel:datapoints:InsightRuleContributor' :: [InsightRuleContributorDatapoint]
datapoints = 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 :: Lens' InsightRuleContributor [Text]
insightRuleContributor_keys = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 :: Lens' InsightRuleContributor Double
insightRuleContributor_approximateAggregateValue = 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 :: Lens' InsightRuleContributor [InsightRuleContributorDatapoint]
insightRuleContributor_datapoints = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Data.FromXML InsightRuleContributor where
  parseXML :: [Node] -> Either String InsightRuleContributor
parseXML [Node]
x =
    [Text]
-> Double
-> [InsightRuleContributorDatapoint]
-> InsightRuleContributor
InsightRuleContributor'
      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
"Keys"
                      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 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 a
Data..@ Text
"ApproximateAggregateValue")
      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
"Datapoints"
                      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 a. FromXML a => Text -> [Node] -> Either String [a]
Data.parseXMLList Text
"member"
                  )

instance Prelude.Hashable InsightRuleContributor where
  hashWithSalt :: Int -> InsightRuleContributor -> Int
hashWithSalt Int
_salt InsightRuleContributor' {Double
[Text]
[InsightRuleContributorDatapoint]
datapoints :: [InsightRuleContributorDatapoint]
approximateAggregateValue :: Double
keys :: [Text]
$sel:datapoints:InsightRuleContributor' :: InsightRuleContributor -> [InsightRuleContributorDatapoint]
$sel:approximateAggregateValue:InsightRuleContributor' :: InsightRuleContributor -> Double
$sel:keys:InsightRuleContributor' :: InsightRuleContributor -> [Text]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [Text]
keys
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Double
approximateAggregateValue
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [InsightRuleContributorDatapoint]
datapoints

instance Prelude.NFData InsightRuleContributor where
  rnf :: InsightRuleContributor -> ()
rnf InsightRuleContributor' {Double
[Text]
[InsightRuleContributorDatapoint]
datapoints :: [InsightRuleContributorDatapoint]
approximateAggregateValue :: Double
keys :: [Text]
$sel:datapoints:InsightRuleContributor' :: InsightRuleContributor -> [InsightRuleContributorDatapoint]
$sel:approximateAggregateValue:InsightRuleContributor' :: InsightRuleContributor -> Double
$sel:keys:InsightRuleContributor' :: InsightRuleContributor -> [Text]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf [Text]
keys
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Double
approximateAggregateValue
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [InsightRuleContributorDatapoint]
datapoints