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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | This structure contains the definition for a Contributor Insights rule.
--
-- /See:/ 'newInsightRule' smart constructor.
data InsightRule = InsightRule'
  { -- | The name of the rule.
    InsightRule -> Text
name :: Prelude.Text,
    -- | Indicates whether the rule is enabled or disabled.
    InsightRule -> Text
state :: Prelude.Text,
    -- | For rules that you create, this is always
    -- @{\"Name\": \"CloudWatchLogRule\", \"Version\": 1}@. For built-in rules,
    -- this is @{\"Name\": \"ServiceLogRule\", \"Version\": 1}@
    InsightRule -> Text
schema :: Prelude.Text,
    -- | The definition of the rule, as a JSON object. The definition contains
    -- the keywords used to define contributors, the value to aggregate on if
    -- this rule returns a sum instead of a count, and the filters. For details
    -- on the valid syntax, see
    -- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/ContributorInsights-RuleSyntax.html Contributor Insights Rule Syntax>.
    InsightRule -> Text
definition :: Prelude.Text
  }
  deriving (InsightRule -> InsightRule -> Bool
(InsightRule -> InsightRule -> Bool)
-> (InsightRule -> InsightRule -> Bool) -> Eq InsightRule
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: InsightRule -> InsightRule -> Bool
$c/= :: InsightRule -> InsightRule -> Bool
== :: InsightRule -> InsightRule -> Bool
$c== :: InsightRule -> InsightRule -> Bool
Prelude.Eq, ReadPrec [InsightRule]
ReadPrec InsightRule
Int -> ReadS InsightRule
ReadS [InsightRule]
(Int -> ReadS InsightRule)
-> ReadS [InsightRule]
-> ReadPrec InsightRule
-> ReadPrec [InsightRule]
-> Read InsightRule
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [InsightRule]
$creadListPrec :: ReadPrec [InsightRule]
readPrec :: ReadPrec InsightRule
$creadPrec :: ReadPrec InsightRule
readList :: ReadS [InsightRule]
$creadList :: ReadS [InsightRule]
readsPrec :: Int -> ReadS InsightRule
$creadsPrec :: Int -> ReadS InsightRule
Prelude.Read, Int -> InsightRule -> ShowS
[InsightRule] -> ShowS
InsightRule -> String
(Int -> InsightRule -> ShowS)
-> (InsightRule -> String)
-> ([InsightRule] -> ShowS)
-> Show InsightRule
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InsightRule] -> ShowS
$cshowList :: [InsightRule] -> ShowS
show :: InsightRule -> String
$cshow :: InsightRule -> String
showsPrec :: Int -> InsightRule -> ShowS
$cshowsPrec :: Int -> InsightRule -> ShowS
Prelude.Show, (forall x. InsightRule -> Rep InsightRule x)
-> (forall x. Rep InsightRule x -> InsightRule)
-> Generic InsightRule
forall x. Rep InsightRule x -> InsightRule
forall x. InsightRule -> Rep InsightRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep InsightRule x -> InsightRule
$cfrom :: forall x. InsightRule -> Rep InsightRule x
Prelude.Generic)

-- |
-- Create a value of 'InsightRule' 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:
--
-- 'name', 'insightRule_name' - The name of the rule.
--
-- 'state', 'insightRule_state' - Indicates whether the rule is enabled or disabled.
--
-- 'schema', 'insightRule_schema' - For rules that you create, this is always
-- @{\"Name\": \"CloudWatchLogRule\", \"Version\": 1}@. For built-in rules,
-- this is @{\"Name\": \"ServiceLogRule\", \"Version\": 1}@
--
-- 'definition', 'insightRule_definition' - The definition of the rule, as a JSON object. The definition contains
-- the keywords used to define contributors, the value to aggregate on if
-- this rule returns a sum instead of a count, and the filters. For details
-- on the valid syntax, see
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/ContributorInsights-RuleSyntax.html Contributor Insights Rule Syntax>.
newInsightRule ::
  -- | 'name'
  Prelude.Text ->
  -- | 'state'
  Prelude.Text ->
  -- | 'schema'
  Prelude.Text ->
  -- | 'definition'
  Prelude.Text ->
  InsightRule
newInsightRule :: Text -> Text -> Text -> Text -> InsightRule
newInsightRule Text
pName_ Text
pState_ Text
pSchema_ Text
pDefinition_ =
  InsightRule' :: Text -> Text -> Text -> Text -> InsightRule
InsightRule'
    { $sel:name:InsightRule' :: Text
name = Text
pName_,
      $sel:state:InsightRule' :: Text
state = Text
pState_,
      $sel:schema:InsightRule' :: Text
schema = Text
pSchema_,
      $sel:definition:InsightRule' :: Text
definition = Text
pDefinition_
    }

-- | The name of the rule.
insightRule_name :: Lens.Lens' InsightRule Prelude.Text
insightRule_name :: (Text -> f Text) -> InsightRule -> f InsightRule
insightRule_name = (InsightRule -> Text)
-> (InsightRule -> Text -> InsightRule)
-> Lens InsightRule InsightRule Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InsightRule' {Text
name :: Text
$sel:name:InsightRule' :: InsightRule -> Text
name} -> Text
name) (\s :: InsightRule
s@InsightRule' {} Text
a -> InsightRule
s {$sel:name:InsightRule' :: Text
name = Text
a} :: InsightRule)

-- | Indicates whether the rule is enabled or disabled.
insightRule_state :: Lens.Lens' InsightRule Prelude.Text
insightRule_state :: (Text -> f Text) -> InsightRule -> f InsightRule
insightRule_state = (InsightRule -> Text)
-> (InsightRule -> Text -> InsightRule)
-> Lens InsightRule InsightRule Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InsightRule' {Text
state :: Text
$sel:state:InsightRule' :: InsightRule -> Text
state} -> Text
state) (\s :: InsightRule
s@InsightRule' {} Text
a -> InsightRule
s {$sel:state:InsightRule' :: Text
state = Text
a} :: InsightRule)

-- | For rules that you create, this is always
-- @{\"Name\": \"CloudWatchLogRule\", \"Version\": 1}@. For built-in rules,
-- this is @{\"Name\": \"ServiceLogRule\", \"Version\": 1}@
insightRule_schema :: Lens.Lens' InsightRule Prelude.Text
insightRule_schema :: (Text -> f Text) -> InsightRule -> f InsightRule
insightRule_schema = (InsightRule -> Text)
-> (InsightRule -> Text -> InsightRule)
-> Lens InsightRule InsightRule Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InsightRule' {Text
schema :: Text
$sel:schema:InsightRule' :: InsightRule -> Text
schema} -> Text
schema) (\s :: InsightRule
s@InsightRule' {} Text
a -> InsightRule
s {$sel:schema:InsightRule' :: Text
schema = Text
a} :: InsightRule)

-- | The definition of the rule, as a JSON object. The definition contains
-- the keywords used to define contributors, the value to aggregate on if
-- this rule returns a sum instead of a count, and the filters. For details
-- on the valid syntax, see
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/ContributorInsights-RuleSyntax.html Contributor Insights Rule Syntax>.
insightRule_definition :: Lens.Lens' InsightRule Prelude.Text
insightRule_definition :: (Text -> f Text) -> InsightRule -> f InsightRule
insightRule_definition = (InsightRule -> Text)
-> (InsightRule -> Text -> InsightRule)
-> Lens InsightRule InsightRule Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InsightRule' {Text
definition :: Text
$sel:definition:InsightRule' :: InsightRule -> Text
definition} -> Text
definition) (\s :: InsightRule
s@InsightRule' {} Text
a -> InsightRule
s {$sel:definition:InsightRule' :: Text
definition = Text
a} :: InsightRule)

instance Core.FromXML InsightRule where
  parseXML :: [Node] -> Either String InsightRule
parseXML [Node]
x =
    Text -> Text -> Text -> Text -> InsightRule
InsightRule'
      (Text -> Text -> Text -> Text -> InsightRule)
-> Either String Text
-> Either String (Text -> Text -> Text -> InsightRule)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String Text
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"Name")
      Either String (Text -> Text -> Text -> InsightRule)
-> Either String Text
-> Either String (Text -> Text -> InsightRule)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Text
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"State")
      Either String (Text -> Text -> InsightRule)
-> Either String Text -> Either String (Text -> InsightRule)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Text
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"Schema")
      Either String (Text -> InsightRule)
-> Either String Text -> Either String InsightRule
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Text
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"Definition")

instance Prelude.Hashable InsightRule

instance Prelude.NFData InsightRule