{-# 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.CloudWatchEvents.Types.Rule
-- 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.CloudWatchEvents.Types.Rule where

import Amazonka.CloudWatchEvents.Types.RuleState
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 information about a rule in Amazon EventBridge.
--
-- /See:/ 'newRule' smart constructor.
data Rule = Rule'
  { -- | The Amazon Resource Name (ARN) of the rule.
    Rule -> Maybe Text
arn :: Prelude.Maybe Prelude.Text,
    -- | The description of the rule.
    Rule -> Maybe Text
description :: Prelude.Maybe Prelude.Text,
    -- | The name or ARN of the event bus associated with the rule. If you omit
    -- this, the default event bus is used.
    Rule -> Maybe Text
eventBusName :: Prelude.Maybe Prelude.Text,
    -- | The event pattern of the rule. For more information, see
    -- <https://docs.aws.amazon.com/eventbridge/latest/userguide/eventbridge-and-event-patterns.html Events and Event Patterns>
    -- in the /Amazon EventBridge User Guide/.
    Rule -> Maybe Text
eventPattern :: Prelude.Maybe Prelude.Text,
    -- | If the rule was created on behalf of your account by an Amazon Web
    -- Services service, this field displays the principal name of the service
    -- that created the rule.
    Rule -> Maybe Text
managedBy :: Prelude.Maybe Prelude.Text,
    -- | The name of the rule.
    Rule -> Maybe Text
name :: Prelude.Maybe Prelude.Text,
    -- | The Amazon Resource Name (ARN) of the role that is used for target
    -- invocation.
    --
    -- If you\'re setting an event bus in another account as the target and
    -- that account granted permission to your account through an organization
    -- instead of directly by the account ID, you must specify a @RoleArn@ with
    -- proper permissions in the @Target@ structure, instead of here in this
    -- parameter.
    Rule -> Maybe Text
roleArn :: Prelude.Maybe Prelude.Text,
    -- | The scheduling expression. For example, \"cron(0 20 * * ? *)\", \"rate(5
    -- minutes)\". For more information, see
    -- <https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-create-rule-schedule.html Creating an Amazon EventBridge rule that runs on a schedule>.
    Rule -> Maybe Text
scheduleExpression :: Prelude.Maybe Prelude.Text,
    -- | The state of the rule.
    Rule -> Maybe RuleState
state :: Prelude.Maybe RuleState
  }
  deriving (Rule -> Rule -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Rule -> Rule -> Bool
$c/= :: Rule -> Rule -> Bool
== :: Rule -> Rule -> Bool
$c== :: Rule -> Rule -> Bool
Prelude.Eq, ReadPrec [Rule]
ReadPrec Rule
Int -> ReadS Rule
ReadS [Rule]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Rule]
$creadListPrec :: ReadPrec [Rule]
readPrec :: ReadPrec Rule
$creadPrec :: ReadPrec Rule
readList :: ReadS [Rule]
$creadList :: ReadS [Rule]
readsPrec :: Int -> ReadS Rule
$creadsPrec :: Int -> ReadS Rule
Prelude.Read, Int -> Rule -> ShowS
[Rule] -> ShowS
Rule -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Rule] -> ShowS
$cshowList :: [Rule] -> ShowS
show :: Rule -> String
$cshow :: Rule -> String
showsPrec :: Int -> Rule -> ShowS
$cshowsPrec :: Int -> Rule -> ShowS
Prelude.Show, forall x. Rep Rule x -> Rule
forall x. Rule -> Rep Rule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Rule x -> Rule
$cfrom :: forall x. Rule -> Rep Rule x
Prelude.Generic)

-- |
-- Create a value of 'Rule' 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:
--
-- 'arn', 'rule_arn' - The Amazon Resource Name (ARN) of the rule.
--
-- 'description', 'rule_description' - The description of the rule.
--
-- 'eventBusName', 'rule_eventBusName' - The name or ARN of the event bus associated with the rule. If you omit
-- this, the default event bus is used.
--
-- 'eventPattern', 'rule_eventPattern' - The event pattern of the rule. For more information, see
-- <https://docs.aws.amazon.com/eventbridge/latest/userguide/eventbridge-and-event-patterns.html Events and Event Patterns>
-- in the /Amazon EventBridge User Guide/.
--
-- 'managedBy', 'rule_managedBy' - If the rule was created on behalf of your account by an Amazon Web
-- Services service, this field displays the principal name of the service
-- that created the rule.
--
-- 'name', 'rule_name' - The name of the rule.
--
-- 'roleArn', 'rule_roleArn' - The Amazon Resource Name (ARN) of the role that is used for target
-- invocation.
--
-- If you\'re setting an event bus in another account as the target and
-- that account granted permission to your account through an organization
-- instead of directly by the account ID, you must specify a @RoleArn@ with
-- proper permissions in the @Target@ structure, instead of here in this
-- parameter.
--
-- 'scheduleExpression', 'rule_scheduleExpression' - The scheduling expression. For example, \"cron(0 20 * * ? *)\", \"rate(5
-- minutes)\". For more information, see
-- <https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-create-rule-schedule.html Creating an Amazon EventBridge rule that runs on a schedule>.
--
-- 'state', 'rule_state' - The state of the rule.
newRule ::
  Rule
newRule :: Rule
newRule =
  Rule'
    { $sel:arn:Rule' :: Maybe Text
arn = forall a. Maybe a
Prelude.Nothing,
      $sel:description:Rule' :: Maybe Text
description = forall a. Maybe a
Prelude.Nothing,
      $sel:eventBusName:Rule' :: Maybe Text
eventBusName = forall a. Maybe a
Prelude.Nothing,
      $sel:eventPattern:Rule' :: Maybe Text
eventPattern = forall a. Maybe a
Prelude.Nothing,
      $sel:managedBy:Rule' :: Maybe Text
managedBy = forall a. Maybe a
Prelude.Nothing,
      $sel:name:Rule' :: Maybe Text
name = forall a. Maybe a
Prelude.Nothing,
      $sel:roleArn:Rule' :: Maybe Text
roleArn = forall a. Maybe a
Prelude.Nothing,
      $sel:scheduleExpression:Rule' :: Maybe Text
scheduleExpression = forall a. Maybe a
Prelude.Nothing,
      $sel:state:Rule' :: Maybe RuleState
state = forall a. Maybe a
Prelude.Nothing
    }

-- | The Amazon Resource Name (ARN) of the rule.
rule_arn :: Lens.Lens' Rule (Prelude.Maybe Prelude.Text)
rule_arn :: Lens' Rule (Maybe Text)
rule_arn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Rule' {Maybe Text
arn :: Maybe Text
$sel:arn:Rule' :: Rule -> Maybe Text
arn} -> Maybe Text
arn) (\s :: Rule
s@Rule' {} Maybe Text
a -> Rule
s {$sel:arn:Rule' :: Maybe Text
arn = Maybe Text
a} :: Rule)

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

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

-- | The event pattern of the rule. For more information, see
-- <https://docs.aws.amazon.com/eventbridge/latest/userguide/eventbridge-and-event-patterns.html Events and Event Patterns>
-- in the /Amazon EventBridge User Guide/.
rule_eventPattern :: Lens.Lens' Rule (Prelude.Maybe Prelude.Text)
rule_eventPattern :: Lens' Rule (Maybe Text)
rule_eventPattern = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Rule' {Maybe Text
eventPattern :: Maybe Text
$sel:eventPattern:Rule' :: Rule -> Maybe Text
eventPattern} -> Maybe Text
eventPattern) (\s :: Rule
s@Rule' {} Maybe Text
a -> Rule
s {$sel:eventPattern:Rule' :: Maybe Text
eventPattern = Maybe Text
a} :: Rule)

-- | If the rule was created on behalf of your account by an Amazon Web
-- Services service, this field displays the principal name of the service
-- that created the rule.
rule_managedBy :: Lens.Lens' Rule (Prelude.Maybe Prelude.Text)
rule_managedBy :: Lens' Rule (Maybe Text)
rule_managedBy = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Rule' {Maybe Text
managedBy :: Maybe Text
$sel:managedBy:Rule' :: Rule -> Maybe Text
managedBy} -> Maybe Text
managedBy) (\s :: Rule
s@Rule' {} Maybe Text
a -> Rule
s {$sel:managedBy:Rule' :: Maybe Text
managedBy = Maybe Text
a} :: Rule)

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

-- | The Amazon Resource Name (ARN) of the role that is used for target
-- invocation.
--
-- If you\'re setting an event bus in another account as the target and
-- that account granted permission to your account through an organization
-- instead of directly by the account ID, you must specify a @RoleArn@ with
-- proper permissions in the @Target@ structure, instead of here in this
-- parameter.
rule_roleArn :: Lens.Lens' Rule (Prelude.Maybe Prelude.Text)
rule_roleArn :: Lens' Rule (Maybe Text)
rule_roleArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Rule' {Maybe Text
roleArn :: Maybe Text
$sel:roleArn:Rule' :: Rule -> Maybe Text
roleArn} -> Maybe Text
roleArn) (\s :: Rule
s@Rule' {} Maybe Text
a -> Rule
s {$sel:roleArn:Rule' :: Maybe Text
roleArn = Maybe Text
a} :: Rule)

-- | The scheduling expression. For example, \"cron(0 20 * * ? *)\", \"rate(5
-- minutes)\". For more information, see
-- <https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-create-rule-schedule.html Creating an Amazon EventBridge rule that runs on a schedule>.
rule_scheduleExpression :: Lens.Lens' Rule (Prelude.Maybe Prelude.Text)
rule_scheduleExpression :: Lens' Rule (Maybe Text)
rule_scheduleExpression = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Rule' {Maybe Text
scheduleExpression :: Maybe Text
$sel:scheduleExpression:Rule' :: Rule -> Maybe Text
scheduleExpression} -> Maybe Text
scheduleExpression) (\s :: Rule
s@Rule' {} Maybe Text
a -> Rule
s {$sel:scheduleExpression:Rule' :: Maybe Text
scheduleExpression = Maybe Text
a} :: Rule)

-- | The state of the rule.
rule_state :: Lens.Lens' Rule (Prelude.Maybe RuleState)
rule_state :: Lens' Rule (Maybe RuleState)
rule_state = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Rule' {Maybe RuleState
state :: Maybe RuleState
$sel:state:Rule' :: Rule -> Maybe RuleState
state} -> Maybe RuleState
state) (\s :: Rule
s@Rule' {} Maybe RuleState
a -> Rule
s {$sel:state:Rule' :: Maybe RuleState
state = Maybe RuleState
a} :: Rule)

instance Data.FromJSON Rule where
  parseJSON :: Value -> Parser Rule
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Rule"
      ( \Object
x ->
          Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe RuleState
-> Rule
Rule'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Arn")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Description")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"EventBusName")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"EventPattern")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"ManagedBy")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Name")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"RoleArn")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"ScheduleExpression")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"State")
      )

instance Prelude.Hashable Rule where
  hashWithSalt :: Int -> Rule -> Int
hashWithSalt Int
_salt Rule' {Maybe Text
Maybe RuleState
state :: Maybe RuleState
scheduleExpression :: Maybe Text
roleArn :: Maybe Text
name :: Maybe Text
managedBy :: Maybe Text
eventPattern :: Maybe Text
eventBusName :: Maybe Text
description :: Maybe Text
arn :: Maybe Text
$sel:state:Rule' :: Rule -> Maybe RuleState
$sel:scheduleExpression:Rule' :: Rule -> Maybe Text
$sel:roleArn:Rule' :: Rule -> Maybe Text
$sel:name:Rule' :: Rule -> Maybe Text
$sel:managedBy:Rule' :: Rule -> Maybe Text
$sel:eventPattern:Rule' :: Rule -> Maybe Text
$sel:eventBusName:Rule' :: Rule -> Maybe Text
$sel:description:Rule' :: Rule -> Maybe Text
$sel:arn:Rule' :: Rule -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
arn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
description
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
eventBusName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
eventPattern
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
managedBy
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
roleArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
scheduleExpression
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe RuleState
state

instance Prelude.NFData Rule where
  rnf :: Rule -> ()
rnf Rule' {Maybe Text
Maybe RuleState
state :: Maybe RuleState
scheduleExpression :: Maybe Text
roleArn :: Maybe Text
name :: Maybe Text
managedBy :: Maybe Text
eventPattern :: Maybe Text
eventBusName :: Maybe Text
description :: Maybe Text
arn :: Maybe Text
$sel:state:Rule' :: Rule -> Maybe RuleState
$sel:scheduleExpression:Rule' :: Rule -> Maybe Text
$sel:roleArn:Rule' :: Rule -> Maybe Text
$sel:name:Rule' :: Rule -> Maybe Text
$sel:managedBy:Rule' :: Rule -> Maybe Text
$sel:eventPattern:Rule' :: Rule -> Maybe Text
$sel:eventBusName:Rule' :: Rule -> Maybe Text
$sel:description:Rule' :: Rule -> Maybe Text
$sel:arn:Rule' :: Rule -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
arn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
description
      seq :: forall a b. a -> b -> b
`Prelude.seq` 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 Text
eventPattern
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
managedBy
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
roleArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
scheduleExpression
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe RuleState
state