{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# 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.EnableInsightRules
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Enables the specified Contributor Insights rules. When rules are
-- enabled, they immediately begin analyzing log data.
module Amazonka.CloudWatch.EnableInsightRules
  ( -- * Creating a Request
    EnableInsightRules (..),
    newEnableInsightRules,

    -- * Request Lenses
    enableInsightRules_ruleNames,

    -- * Destructuring the Response
    EnableInsightRulesResponse (..),
    newEnableInsightRulesResponse,

    -- * Response Lenses
    enableInsightRulesResponse_failures,
    enableInsightRulesResponse_httpStatus,
  )
where

import Amazonka.CloudWatch.Types
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
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newEnableInsightRules' smart constructor.
data EnableInsightRules = EnableInsightRules'
  { -- | An array of the rule names to enable. If you need to find out the names
    -- of your rules, use
    -- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_DescribeInsightRules.html DescribeInsightRules>.
    EnableInsightRules -> [Text]
ruleNames :: [Prelude.Text]
  }
  deriving (EnableInsightRules -> EnableInsightRules -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EnableInsightRules -> EnableInsightRules -> Bool
$c/= :: EnableInsightRules -> EnableInsightRules -> Bool
== :: EnableInsightRules -> EnableInsightRules -> Bool
$c== :: EnableInsightRules -> EnableInsightRules -> Bool
Prelude.Eq, ReadPrec [EnableInsightRules]
ReadPrec EnableInsightRules
Int -> ReadS EnableInsightRules
ReadS [EnableInsightRules]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EnableInsightRules]
$creadListPrec :: ReadPrec [EnableInsightRules]
readPrec :: ReadPrec EnableInsightRules
$creadPrec :: ReadPrec EnableInsightRules
readList :: ReadS [EnableInsightRules]
$creadList :: ReadS [EnableInsightRules]
readsPrec :: Int -> ReadS EnableInsightRules
$creadsPrec :: Int -> ReadS EnableInsightRules
Prelude.Read, Int -> EnableInsightRules -> ShowS
[EnableInsightRules] -> ShowS
EnableInsightRules -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EnableInsightRules] -> ShowS
$cshowList :: [EnableInsightRules] -> ShowS
show :: EnableInsightRules -> String
$cshow :: EnableInsightRules -> String
showsPrec :: Int -> EnableInsightRules -> ShowS
$cshowsPrec :: Int -> EnableInsightRules -> ShowS
Prelude.Show, forall x. Rep EnableInsightRules x -> EnableInsightRules
forall x. EnableInsightRules -> Rep EnableInsightRules x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep EnableInsightRules x -> EnableInsightRules
$cfrom :: forall x. EnableInsightRules -> Rep EnableInsightRules x
Prelude.Generic)

-- |
-- Create a value of 'EnableInsightRules' 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:
--
-- 'ruleNames', 'enableInsightRules_ruleNames' - An array of the rule names to enable. If you need to find out the names
-- of your rules, use
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_DescribeInsightRules.html DescribeInsightRules>.
newEnableInsightRules ::
  EnableInsightRules
newEnableInsightRules :: EnableInsightRules
newEnableInsightRules =
  EnableInsightRules' {$sel:ruleNames:EnableInsightRules' :: [Text]
ruleNames = forall a. Monoid a => a
Prelude.mempty}

-- | An array of the rule names to enable. If you need to find out the names
-- of your rules, use
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_DescribeInsightRules.html DescribeInsightRules>.
enableInsightRules_ruleNames :: Lens.Lens' EnableInsightRules [Prelude.Text]
enableInsightRules_ruleNames :: Lens' EnableInsightRules [Text]
enableInsightRules_ruleNames = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EnableInsightRules' {[Text]
ruleNames :: [Text]
$sel:ruleNames:EnableInsightRules' :: EnableInsightRules -> [Text]
ruleNames} -> [Text]
ruleNames) (\s :: EnableInsightRules
s@EnableInsightRules' {} [Text]
a -> EnableInsightRules
s {$sel:ruleNames:EnableInsightRules' :: [Text]
ruleNames = [Text]
a} :: EnableInsightRules) 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 Core.AWSRequest EnableInsightRules where
  type
    AWSResponse EnableInsightRules =
      EnableInsightRulesResponse
  request :: (Service -> Service)
-> EnableInsightRules -> Request EnableInsightRules
request Service -> Service
overrides =
    forall a. ToRequest a => Service -> a -> Request a
Request.postQuery (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy EnableInsightRules
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse EnableInsightRules)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
Text
-> (Int
    -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveXMLWrapper
      Text
"EnableInsightRulesResult"
      ( \Int
s ResponseHeaders
h [Node]
x ->
          Maybe [PartialFailure] -> Int -> EnableInsightRulesResponse
EnableInsightRulesResponse'
            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
"Failures"
                            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 (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (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.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable EnableInsightRules where
  hashWithSalt :: Int -> EnableInsightRules -> Int
hashWithSalt Int
_salt EnableInsightRules' {[Text]
ruleNames :: [Text]
$sel:ruleNames:EnableInsightRules' :: EnableInsightRules -> [Text]
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [Text]
ruleNames

instance Prelude.NFData EnableInsightRules where
  rnf :: EnableInsightRules -> ()
rnf EnableInsightRules' {[Text]
ruleNames :: [Text]
$sel:ruleNames:EnableInsightRules' :: EnableInsightRules -> [Text]
..} = forall a. NFData a => a -> ()
Prelude.rnf [Text]
ruleNames

instance Data.ToHeaders EnableInsightRules where
  toHeaders :: EnableInsightRules -> ResponseHeaders
toHeaders = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

instance Data.ToPath EnableInsightRules where
  toPath :: EnableInsightRules -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Data.ToQuery EnableInsightRules where
  toQuery :: EnableInsightRules -> QueryString
toQuery EnableInsightRules' {[Text]
ruleNames :: [Text]
$sel:ruleNames:EnableInsightRules' :: EnableInsightRules -> [Text]
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action"
          forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: (ByteString
"EnableInsightRules" :: Prelude.ByteString),
        ByteString
"Version"
          forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: (ByteString
"2010-08-01" :: Prelude.ByteString),
        ByteString
"RuleNames"
          forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: forall a.
(IsList a, ToQuery (Item a)) =>
ByteString -> a -> QueryString
Data.toQueryList ByteString
"member" [Text]
ruleNames
      ]

-- | /See:/ 'newEnableInsightRulesResponse' smart constructor.
data EnableInsightRulesResponse = EnableInsightRulesResponse'
  { -- | An array listing the rules that could not be enabled. You cannot disable
    -- or enable built-in rules.
    EnableInsightRulesResponse -> Maybe [PartialFailure]
failures :: Prelude.Maybe [PartialFailure],
    -- | The response's http status code.
    EnableInsightRulesResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (EnableInsightRulesResponse -> EnableInsightRulesResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EnableInsightRulesResponse -> EnableInsightRulesResponse -> Bool
$c/= :: EnableInsightRulesResponse -> EnableInsightRulesResponse -> Bool
== :: EnableInsightRulesResponse -> EnableInsightRulesResponse -> Bool
$c== :: EnableInsightRulesResponse -> EnableInsightRulesResponse -> Bool
Prelude.Eq, ReadPrec [EnableInsightRulesResponse]
ReadPrec EnableInsightRulesResponse
Int -> ReadS EnableInsightRulesResponse
ReadS [EnableInsightRulesResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EnableInsightRulesResponse]
$creadListPrec :: ReadPrec [EnableInsightRulesResponse]
readPrec :: ReadPrec EnableInsightRulesResponse
$creadPrec :: ReadPrec EnableInsightRulesResponse
readList :: ReadS [EnableInsightRulesResponse]
$creadList :: ReadS [EnableInsightRulesResponse]
readsPrec :: Int -> ReadS EnableInsightRulesResponse
$creadsPrec :: Int -> ReadS EnableInsightRulesResponse
Prelude.Read, Int -> EnableInsightRulesResponse -> ShowS
[EnableInsightRulesResponse] -> ShowS
EnableInsightRulesResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EnableInsightRulesResponse] -> ShowS
$cshowList :: [EnableInsightRulesResponse] -> ShowS
show :: EnableInsightRulesResponse -> String
$cshow :: EnableInsightRulesResponse -> String
showsPrec :: Int -> EnableInsightRulesResponse -> ShowS
$cshowsPrec :: Int -> EnableInsightRulesResponse -> ShowS
Prelude.Show, forall x.
Rep EnableInsightRulesResponse x -> EnableInsightRulesResponse
forall x.
EnableInsightRulesResponse -> Rep EnableInsightRulesResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep EnableInsightRulesResponse x -> EnableInsightRulesResponse
$cfrom :: forall x.
EnableInsightRulesResponse -> Rep EnableInsightRulesResponse x
Prelude.Generic)

-- |
-- Create a value of 'EnableInsightRulesResponse' 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:
--
-- 'failures', 'enableInsightRulesResponse_failures' - An array listing the rules that could not be enabled. You cannot disable
-- or enable built-in rules.
--
-- 'httpStatus', 'enableInsightRulesResponse_httpStatus' - The response's http status code.
newEnableInsightRulesResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  EnableInsightRulesResponse
newEnableInsightRulesResponse :: Int -> EnableInsightRulesResponse
newEnableInsightRulesResponse Int
pHttpStatus_ =
  EnableInsightRulesResponse'
    { $sel:failures:EnableInsightRulesResponse' :: Maybe [PartialFailure]
failures =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:EnableInsightRulesResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | An array listing the rules that could not be enabled. You cannot disable
-- or enable built-in rules.
enableInsightRulesResponse_failures :: Lens.Lens' EnableInsightRulesResponse (Prelude.Maybe [PartialFailure])
enableInsightRulesResponse_failures :: Lens' EnableInsightRulesResponse (Maybe [PartialFailure])
enableInsightRulesResponse_failures = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EnableInsightRulesResponse' {Maybe [PartialFailure]
failures :: Maybe [PartialFailure]
$sel:failures:EnableInsightRulesResponse' :: EnableInsightRulesResponse -> Maybe [PartialFailure]
failures} -> Maybe [PartialFailure]
failures) (\s :: EnableInsightRulesResponse
s@EnableInsightRulesResponse' {} Maybe [PartialFailure]
a -> EnableInsightRulesResponse
s {$sel:failures:EnableInsightRulesResponse' :: Maybe [PartialFailure]
failures = Maybe [PartialFailure]
a} :: EnableInsightRulesResponse) 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 response's http status code.
enableInsightRulesResponse_httpStatus :: Lens.Lens' EnableInsightRulesResponse Prelude.Int
enableInsightRulesResponse_httpStatus :: Lens' EnableInsightRulesResponse Int
enableInsightRulesResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EnableInsightRulesResponse' {Int
httpStatus :: Int
$sel:httpStatus:EnableInsightRulesResponse' :: EnableInsightRulesResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: EnableInsightRulesResponse
s@EnableInsightRulesResponse' {} Int
a -> EnableInsightRulesResponse
s {$sel:httpStatus:EnableInsightRulesResponse' :: Int
httpStatus = Int
a} :: EnableInsightRulesResponse)

instance Prelude.NFData EnableInsightRulesResponse where
  rnf :: EnableInsightRulesResponse -> ()
rnf EnableInsightRulesResponse' {Int
Maybe [PartialFailure]
httpStatus :: Int
failures :: Maybe [PartialFailure]
$sel:httpStatus:EnableInsightRulesResponse' :: EnableInsightRulesResponse -> Int
$sel:failures:EnableInsightRulesResponse' :: EnableInsightRulesResponse -> Maybe [PartialFailure]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [PartialFailure]
failures
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus