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

import Amazonka.CloudWatchEvents.Types.RuleState
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Contains information about a rule in Amazon EventBridge.
--
-- /See:/ 'newRule' smart constructor.
data Rule = 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 -> Maybe Text
eventPattern :: Prelude.Maybe Prelude.Text,
    -- | The state of the rule.
    Rule -> Maybe RuleState
state :: Prelude.Maybe RuleState,
    -- | The Amazon Resource Name (ARN) of the rule.
    Rule -> Maybe Text
arn :: 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 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 name of the rule.
    Rule -> Maybe Text
name :: Prelude.Maybe Prelude.Text,
    -- | The description of the rule.
    Rule -> Maybe Text
description :: 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 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
  }
  deriving (Rule -> Rule -> Bool
(Rule -> Rule -> Bool) -> (Rule -> Rule -> Bool) -> Eq Rule
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]
(Int -> ReadS Rule)
-> ReadS [Rule] -> ReadPrec Rule -> ReadPrec [Rule] -> Read 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
(Int -> Rule -> ShowS)
-> (Rule -> String) -> ([Rule] -> ShowS) -> Show Rule
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. Rule -> Rep Rule x)
-> (forall x. Rep Rule x -> Rule) -> Generic Rule
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:
--
-- '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/.
--
-- 'state', 'rule_state' - The state of the rule.
--
-- 'arn', 'rule_arn' - The Amazon Resource Name (ARN) 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.
--
-- '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>.
--
-- 'name', 'rule_name' - The name of the rule.
--
-- 'description', 'rule_description' - The description of the rule.
--
-- '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.
--
-- '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.
newRule ::
  Rule
newRule :: Rule
newRule =
  Rule' :: Maybe Text
-> Maybe RuleState
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Rule
Rule'
    { $sel:eventPattern:Rule' :: Maybe Text
eventPattern = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:state:Rule' :: Maybe RuleState
state = Maybe RuleState
forall a. Maybe a
Prelude.Nothing,
      $sel:arn:Rule' :: Maybe Text
arn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:eventBusName:Rule' :: Maybe Text
eventBusName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:scheduleExpression:Rule' :: Maybe Text
scheduleExpression = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:name:Rule' :: Maybe Text
name = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:description:Rule' :: Maybe Text
description = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:managedBy:Rule' :: Maybe Text
managedBy = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:roleArn:Rule' :: Maybe Text
roleArn = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | 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 :: (Maybe Text -> f (Maybe Text)) -> Rule -> f Rule
rule_eventPattern = (Rule -> Maybe Text)
-> (Rule -> Maybe Text -> Rule)
-> Lens Rule Rule (Maybe Text) (Maybe Text)
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)

-- | The state of the rule.
rule_state :: Lens.Lens' Rule (Prelude.Maybe RuleState)
rule_state :: (Maybe RuleState -> f (Maybe RuleState)) -> Rule -> f Rule
rule_state = (Rule -> Maybe RuleState)
-> (Rule -> Maybe RuleState -> Rule)
-> Lens Rule Rule (Maybe RuleState) (Maybe RuleState)
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)

-- | The Amazon Resource Name (ARN) of the rule.
rule_arn :: Lens.Lens' Rule (Prelude.Maybe Prelude.Text)
rule_arn :: (Maybe Text -> f (Maybe Text)) -> Rule -> f Rule
rule_arn = (Rule -> Maybe Text)
-> (Rule -> Maybe Text -> Rule)
-> Lens Rule Rule (Maybe Text) (Maybe Text)
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 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 :: (Maybe Text -> f (Maybe Text)) -> Rule -> f Rule
rule_eventBusName = (Rule -> Maybe Text)
-> (Rule -> Maybe Text -> Rule)
-> Lens Rule Rule (Maybe Text) (Maybe Text)
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 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 :: (Maybe Text -> f (Maybe Text)) -> Rule -> f Rule
rule_scheduleExpression = (Rule -> Maybe Text)
-> (Rule -> Maybe Text -> Rule)
-> Lens Rule Rule (Maybe Text) (Maybe Text)
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 name of the rule.
rule_name :: Lens.Lens' Rule (Prelude.Maybe Prelude.Text)
rule_name :: (Maybe Text -> f (Maybe Text)) -> Rule -> f Rule
rule_name = (Rule -> Maybe Text)
-> (Rule -> Maybe Text -> Rule)
-> Lens Rule Rule (Maybe Text) (Maybe Text)
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 description of the rule.
rule_description :: Lens.Lens' Rule (Prelude.Maybe Prelude.Text)
rule_description :: (Maybe Text -> f (Maybe Text)) -> Rule -> f Rule
rule_description = (Rule -> Maybe Text)
-> (Rule -> Maybe Text -> Rule)
-> Lens Rule Rule (Maybe Text) (Maybe Text)
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)

-- | 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 :: (Maybe Text -> f (Maybe Text)) -> Rule -> f Rule
rule_managedBy = (Rule -> Maybe Text)
-> (Rule -> Maybe Text -> Rule)
-> Lens Rule Rule (Maybe Text) (Maybe Text)
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 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 :: (Maybe Text -> f (Maybe Text)) -> Rule -> f Rule
rule_roleArn = (Rule -> Maybe Text)
-> (Rule -> Maybe Text -> Rule)
-> Lens Rule Rule (Maybe Text) (Maybe Text)
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)

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

instance Prelude.Hashable Rule

instance Prelude.NFData Rule