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

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

-- | Contains the information that\'s required to enable a managed
-- Contributor Insights rule for an Amazon Web Services resource.
--
-- /See:/ 'newManagedRule' smart constructor.
data ManagedRule = ManagedRule'
  { -- | A list of key-value pairs that you can associate with a managed
    -- Contributor Insights rule. You can associate as many as 50 tags with a
    -- rule. Tags can help you organize and categorize your resources. You also
    -- can use them to scope user permissions by granting a user permission to
    -- access or change only the resources that have certain tag values. To
    -- associate tags with a rule, you must have the @cloudwatch:TagResource@
    -- permission in addition to the @cloudwatch:PutInsightRule@ permission. If
    -- you are using this operation to update an existing Contributor Insights
    -- rule, any tags that you specify in this parameter are ignored. To change
    -- the tags of an existing rule, use @TagResource@.
    ManagedRule -> Maybe [Tag]
tags :: Prelude.Maybe [Tag],
    -- | The template name for the managed Contributor Insights rule, as returned
    -- by @ListManagedInsightRules@.
    ManagedRule -> Text
templateName :: Prelude.Text,
    -- | The ARN of an Amazon Web Services resource that has managed Contributor
    -- Insights rules.
    ManagedRule -> Text
resourceARN :: Prelude.Text
  }
  deriving (ManagedRule -> ManagedRule -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ManagedRule -> ManagedRule -> Bool
$c/= :: ManagedRule -> ManagedRule -> Bool
== :: ManagedRule -> ManagedRule -> Bool
$c== :: ManagedRule -> ManagedRule -> Bool
Prelude.Eq, ReadPrec [ManagedRule]
ReadPrec ManagedRule
Int -> ReadS ManagedRule
ReadS [ManagedRule]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ManagedRule]
$creadListPrec :: ReadPrec [ManagedRule]
readPrec :: ReadPrec ManagedRule
$creadPrec :: ReadPrec ManagedRule
readList :: ReadS [ManagedRule]
$creadList :: ReadS [ManagedRule]
readsPrec :: Int -> ReadS ManagedRule
$creadsPrec :: Int -> ReadS ManagedRule
Prelude.Read, Int -> ManagedRule -> ShowS
[ManagedRule] -> ShowS
ManagedRule -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ManagedRule] -> ShowS
$cshowList :: [ManagedRule] -> ShowS
show :: ManagedRule -> String
$cshow :: ManagedRule -> String
showsPrec :: Int -> ManagedRule -> ShowS
$cshowsPrec :: Int -> ManagedRule -> ShowS
Prelude.Show, forall x. Rep ManagedRule x -> ManagedRule
forall x. ManagedRule -> Rep ManagedRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ManagedRule x -> ManagedRule
$cfrom :: forall x. ManagedRule -> Rep ManagedRule x
Prelude.Generic)

-- |
-- Create a value of 'ManagedRule' 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:
--
-- 'tags', 'managedRule_tags' - A list of key-value pairs that you can associate with a managed
-- Contributor Insights rule. You can associate as many as 50 tags with a
-- rule. Tags can help you organize and categorize your resources. You also
-- can use them to scope user permissions by granting a user permission to
-- access or change only the resources that have certain tag values. To
-- associate tags with a rule, you must have the @cloudwatch:TagResource@
-- permission in addition to the @cloudwatch:PutInsightRule@ permission. If
-- you are using this operation to update an existing Contributor Insights
-- rule, any tags that you specify in this parameter are ignored. To change
-- the tags of an existing rule, use @TagResource@.
--
-- 'templateName', 'managedRule_templateName' - The template name for the managed Contributor Insights rule, as returned
-- by @ListManagedInsightRules@.
--
-- 'resourceARN', 'managedRule_resourceARN' - The ARN of an Amazon Web Services resource that has managed Contributor
-- Insights rules.
newManagedRule ::
  -- | 'templateName'
  Prelude.Text ->
  -- | 'resourceARN'
  Prelude.Text ->
  ManagedRule
newManagedRule :: Text -> Text -> ManagedRule
newManagedRule Text
pTemplateName_ Text
pResourceARN_ =
  ManagedRule'
    { $sel:tags:ManagedRule' :: Maybe [Tag]
tags = forall a. Maybe a
Prelude.Nothing,
      $sel:templateName:ManagedRule' :: Text
templateName = Text
pTemplateName_,
      $sel:resourceARN:ManagedRule' :: Text
resourceARN = Text
pResourceARN_
    }

-- | A list of key-value pairs that you can associate with a managed
-- Contributor Insights rule. You can associate as many as 50 tags with a
-- rule. Tags can help you organize and categorize your resources. You also
-- can use them to scope user permissions by granting a user permission to
-- access or change only the resources that have certain tag values. To
-- associate tags with a rule, you must have the @cloudwatch:TagResource@
-- permission in addition to the @cloudwatch:PutInsightRule@ permission. If
-- you are using this operation to update an existing Contributor Insights
-- rule, any tags that you specify in this parameter are ignored. To change
-- the tags of an existing rule, use @TagResource@.
managedRule_tags :: Lens.Lens' ManagedRule (Prelude.Maybe [Tag])
managedRule_tags :: Lens' ManagedRule (Maybe [Tag])
managedRule_tags = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ManagedRule' {Maybe [Tag]
tags :: Maybe [Tag]
$sel:tags:ManagedRule' :: ManagedRule -> Maybe [Tag]
tags} -> Maybe [Tag]
tags) (\s :: ManagedRule
s@ManagedRule' {} Maybe [Tag]
a -> ManagedRule
s {$sel:tags:ManagedRule' :: Maybe [Tag]
tags = Maybe [Tag]
a} :: ManagedRule) 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 template name for the managed Contributor Insights rule, as returned
-- by @ListManagedInsightRules@.
managedRule_templateName :: Lens.Lens' ManagedRule Prelude.Text
managedRule_templateName :: Lens' ManagedRule Text
managedRule_templateName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ManagedRule' {Text
templateName :: Text
$sel:templateName:ManagedRule' :: ManagedRule -> Text
templateName} -> Text
templateName) (\s :: ManagedRule
s@ManagedRule' {} Text
a -> ManagedRule
s {$sel:templateName:ManagedRule' :: Text
templateName = Text
a} :: ManagedRule)

-- | The ARN of an Amazon Web Services resource that has managed Contributor
-- Insights rules.
managedRule_resourceARN :: Lens.Lens' ManagedRule Prelude.Text
managedRule_resourceARN :: Lens' ManagedRule Text
managedRule_resourceARN = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ManagedRule' {Text
resourceARN :: Text
$sel:resourceARN:ManagedRule' :: ManagedRule -> Text
resourceARN} -> Text
resourceARN) (\s :: ManagedRule
s@ManagedRule' {} Text
a -> ManagedRule
s {$sel:resourceARN:ManagedRule' :: Text
resourceARN = Text
a} :: ManagedRule)

instance Prelude.Hashable ManagedRule where
  hashWithSalt :: Int -> ManagedRule -> Int
hashWithSalt Int
_salt ManagedRule' {Maybe [Tag]
Text
resourceARN :: Text
templateName :: Text
tags :: Maybe [Tag]
$sel:resourceARN:ManagedRule' :: ManagedRule -> Text
$sel:templateName:ManagedRule' :: ManagedRule -> Text
$sel:tags:ManagedRule' :: ManagedRule -> Maybe [Tag]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Tag]
tags
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
templateName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
resourceARN

instance Prelude.NFData ManagedRule where
  rnf :: ManagedRule -> ()
rnf ManagedRule' {Maybe [Tag]
Text
resourceARN :: Text
templateName :: Text
tags :: Maybe [Tag]
$sel:resourceARN:ManagedRule' :: ManagedRule -> Text
$sel:templateName:ManagedRule' :: ManagedRule -> Text
$sel:tags:ManagedRule' :: ManagedRule -> Maybe [Tag]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Tag]
tags
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
templateName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
resourceARN

instance Data.ToQuery ManagedRule where
  toQuery :: ManagedRule -> QueryString
toQuery ManagedRule' {Maybe [Tag]
Text
resourceARN :: Text
templateName :: Text
tags :: Maybe [Tag]
$sel:resourceARN:ManagedRule' :: ManagedRule -> Text
$sel:templateName:ManagedRule' :: ManagedRule -> Text
$sel:tags:ManagedRule' :: ManagedRule -> Maybe [Tag]
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Tags"
          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 [Tag]
tags),
        ByteString
"TemplateName" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Text
templateName,
        ByteString
"ResourceARN" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Text
resourceARN
      ]