{-# 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.CloudWatchEvents.DeleteRule
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Deletes the specified rule.
--
-- Before you can delete the rule, you must remove all targets, using
-- <https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_RemoveTargets.html RemoveTargets>.
--
-- When you delete a rule, incoming events might continue to match to the
-- deleted rule. Allow a short period of time for changes to take effect.
--
-- If you call delete rule multiple times for the same rule, all calls will
-- succeed. When you call delete rule for a non-existent custom eventbus,
-- @ResourceNotFoundException@ is returned.
--
-- Managed rules are rules created and managed by another Amazon Web
-- Services service on your behalf. These rules are created by those other
-- Amazon Web Services services to support functionality in those services.
-- You can delete these rules using the @Force@ option, but you should do
-- so only if you are sure the other service is not still using that rule.
module Amazonka.CloudWatchEvents.DeleteRule
  ( -- * Creating a Request
    DeleteRule (..),
    newDeleteRule,

    -- * Request Lenses
    deleteRule_eventBusName,
    deleteRule_force,
    deleteRule_name,

    -- * Destructuring the Response
    DeleteRuleResponse (..),
    newDeleteRuleResponse,
  )
where

import Amazonka.CloudWatchEvents.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:/ 'newDeleteRule' smart constructor.
data DeleteRule = DeleteRule'
  { -- | The name or ARN of the event bus associated with the rule. If you omit
    -- this, the default event bus is used.
    DeleteRule -> Maybe Text
eventBusName :: Prelude.Maybe Prelude.Text,
    -- | If this is a managed rule, created by an Amazon Web Services service on
    -- your behalf, you must specify @Force@ as @True@ to delete the rule. This
    -- parameter is ignored for rules that are not managed rules. You can check
    -- whether a rule is a managed rule by using @DescribeRule@ or @ListRules@
    -- and checking the @ManagedBy@ field of the response.
    DeleteRule -> Maybe Bool
force :: Prelude.Maybe Prelude.Bool,
    -- | The name of the rule.
    DeleteRule -> Text
name :: Prelude.Text
  }
  deriving (DeleteRule -> DeleteRule -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeleteRule -> DeleteRule -> Bool
$c/= :: DeleteRule -> DeleteRule -> Bool
== :: DeleteRule -> DeleteRule -> Bool
$c== :: DeleteRule -> DeleteRule -> Bool
Prelude.Eq, ReadPrec [DeleteRule]
ReadPrec DeleteRule
Int -> ReadS DeleteRule
ReadS [DeleteRule]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeleteRule]
$creadListPrec :: ReadPrec [DeleteRule]
readPrec :: ReadPrec DeleteRule
$creadPrec :: ReadPrec DeleteRule
readList :: ReadS [DeleteRule]
$creadList :: ReadS [DeleteRule]
readsPrec :: Int -> ReadS DeleteRule
$creadsPrec :: Int -> ReadS DeleteRule
Prelude.Read, Int -> DeleteRule -> ShowS
[DeleteRule] -> ShowS
DeleteRule -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteRule] -> ShowS
$cshowList :: [DeleteRule] -> ShowS
show :: DeleteRule -> String
$cshow :: DeleteRule -> String
showsPrec :: Int -> DeleteRule -> ShowS
$cshowsPrec :: Int -> DeleteRule -> ShowS
Prelude.Show, forall x. Rep DeleteRule x -> DeleteRule
forall x. DeleteRule -> Rep DeleteRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeleteRule x -> DeleteRule
$cfrom :: forall x. DeleteRule -> Rep DeleteRule x
Prelude.Generic)

-- |
-- Create a value of 'DeleteRule' 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:
--
-- 'eventBusName', 'deleteRule_eventBusName' - The name or ARN of the event bus associated with the rule. If you omit
-- this, the default event bus is used.
--
-- 'force', 'deleteRule_force' - If this is a managed rule, created by an Amazon Web Services service on
-- your behalf, you must specify @Force@ as @True@ to delete the rule. This
-- parameter is ignored for rules that are not managed rules. You can check
-- whether a rule is a managed rule by using @DescribeRule@ or @ListRules@
-- and checking the @ManagedBy@ field of the response.
--
-- 'name', 'deleteRule_name' - The name of the rule.
newDeleteRule ::
  -- | 'name'
  Prelude.Text ->
  DeleteRule
newDeleteRule :: Text -> DeleteRule
newDeleteRule Text
pName_ =
  DeleteRule'
    { $sel:eventBusName:DeleteRule' :: Maybe Text
eventBusName = forall a. Maybe a
Prelude.Nothing,
      $sel:force:DeleteRule' :: Maybe Bool
force = forall a. Maybe a
Prelude.Nothing,
      $sel:name:DeleteRule' :: Text
name = Text
pName_
    }

-- | The name or ARN of the event bus associated with the rule. If you omit
-- this, the default event bus is used.
deleteRule_eventBusName :: Lens.Lens' DeleteRule (Prelude.Maybe Prelude.Text)
deleteRule_eventBusName :: Lens' DeleteRule (Maybe Text)
deleteRule_eventBusName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteRule' {Maybe Text
eventBusName :: Maybe Text
$sel:eventBusName:DeleteRule' :: DeleteRule -> Maybe Text
eventBusName} -> Maybe Text
eventBusName) (\s :: DeleteRule
s@DeleteRule' {} Maybe Text
a -> DeleteRule
s {$sel:eventBusName:DeleteRule' :: Maybe Text
eventBusName = Maybe Text
a} :: DeleteRule)

-- | If this is a managed rule, created by an Amazon Web Services service on
-- your behalf, you must specify @Force@ as @True@ to delete the rule. This
-- parameter is ignored for rules that are not managed rules. You can check
-- whether a rule is a managed rule by using @DescribeRule@ or @ListRules@
-- and checking the @ManagedBy@ field of the response.
deleteRule_force :: Lens.Lens' DeleteRule (Prelude.Maybe Prelude.Bool)
deleteRule_force :: Lens' DeleteRule (Maybe Bool)
deleteRule_force = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteRule' {Maybe Bool
force :: Maybe Bool
$sel:force:DeleteRule' :: DeleteRule -> Maybe Bool
force} -> Maybe Bool
force) (\s :: DeleteRule
s@DeleteRule' {} Maybe Bool
a -> DeleteRule
s {$sel:force:DeleteRule' :: Maybe Bool
force = Maybe Bool
a} :: DeleteRule)

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

instance Core.AWSRequest DeleteRule where
  type AWSResponse DeleteRule = DeleteRuleResponse
  request :: (Service -> Service) -> DeleteRule -> Request DeleteRule
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy DeleteRule
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DeleteRule)))
response = forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull DeleteRuleResponse
DeleteRuleResponse'

instance Prelude.Hashable DeleteRule where
  hashWithSalt :: Int -> DeleteRule -> Int
hashWithSalt Int
_salt DeleteRule' {Maybe Bool
Maybe Text
Text
name :: Text
force :: Maybe Bool
eventBusName :: Maybe Text
$sel:name:DeleteRule' :: DeleteRule -> Text
$sel:force:DeleteRule' :: DeleteRule -> Maybe Bool
$sel:eventBusName:DeleteRule' :: DeleteRule -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
eventBusName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
force
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name

instance Prelude.NFData DeleteRule where
  rnf :: DeleteRule -> ()
rnf DeleteRule' {Maybe Bool
Maybe Text
Text
name :: Text
force :: Maybe Bool
eventBusName :: Maybe Text
$sel:name:DeleteRule' :: DeleteRule -> Text
$sel:force:DeleteRule' :: DeleteRule -> Maybe Bool
$sel:eventBusName:DeleteRule' :: DeleteRule -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
eventBusName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
force
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
name

instance Data.ToHeaders DeleteRule where
  toHeaders :: DeleteRule -> [Header]
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              forall a. ToHeader a => HeaderName -> a -> [Header]
Data.=# (ByteString
"AWSEvents.DeleteRule" :: Prelude.ByteString),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> [Header]
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON DeleteRule where
  toJSON :: DeleteRule -> Value
toJSON DeleteRule' {Maybe Bool
Maybe Text
Text
name :: Text
force :: Maybe Bool
eventBusName :: Maybe Text
$sel:name:DeleteRule' :: DeleteRule -> Text
$sel:force:DeleteRule' :: DeleteRule -> Maybe Bool
$sel:eventBusName:DeleteRule' :: DeleteRule -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"EventBusName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
eventBusName,
            (Key
"Force" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
force,
            forall a. a -> Maybe a
Prelude.Just (Key
"Name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
name)
          ]
      )

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

instance Data.ToQuery DeleteRule where
  toQuery :: DeleteRule -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newDeleteRuleResponse' smart constructor.
data DeleteRuleResponse = DeleteRuleResponse'
  {
  }
  deriving (DeleteRuleResponse -> DeleteRuleResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeleteRuleResponse -> DeleteRuleResponse -> Bool
$c/= :: DeleteRuleResponse -> DeleteRuleResponse -> Bool
== :: DeleteRuleResponse -> DeleteRuleResponse -> Bool
$c== :: DeleteRuleResponse -> DeleteRuleResponse -> Bool
Prelude.Eq, ReadPrec [DeleteRuleResponse]
ReadPrec DeleteRuleResponse
Int -> ReadS DeleteRuleResponse
ReadS [DeleteRuleResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeleteRuleResponse]
$creadListPrec :: ReadPrec [DeleteRuleResponse]
readPrec :: ReadPrec DeleteRuleResponse
$creadPrec :: ReadPrec DeleteRuleResponse
readList :: ReadS [DeleteRuleResponse]
$creadList :: ReadS [DeleteRuleResponse]
readsPrec :: Int -> ReadS DeleteRuleResponse
$creadsPrec :: Int -> ReadS DeleteRuleResponse
Prelude.Read, Int -> DeleteRuleResponse -> ShowS
[DeleteRuleResponse] -> ShowS
DeleteRuleResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteRuleResponse] -> ShowS
$cshowList :: [DeleteRuleResponse] -> ShowS
show :: DeleteRuleResponse -> String
$cshow :: DeleteRuleResponse -> String
showsPrec :: Int -> DeleteRuleResponse -> ShowS
$cshowsPrec :: Int -> DeleteRuleResponse -> ShowS
Prelude.Show, forall x. Rep DeleteRuleResponse x -> DeleteRuleResponse
forall x. DeleteRuleResponse -> Rep DeleteRuleResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeleteRuleResponse x -> DeleteRuleResponse
$cfrom :: forall x. DeleteRuleResponse -> Rep DeleteRuleResponse x
Prelude.Generic)

-- |
-- Create a value of 'DeleteRuleResponse' 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.
newDeleteRuleResponse ::
  DeleteRuleResponse
newDeleteRuleResponse :: DeleteRuleResponse
newDeleteRuleResponse = DeleteRuleResponse
DeleteRuleResponse'

instance Prelude.NFData DeleteRuleResponse where
  rnf :: DeleteRuleResponse -> ()
rnf DeleteRuleResponse
_ = ()