{-# 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.IoT.Types.TopicRulePayload
-- 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.IoT.Types.TopicRulePayload where

import qualified Amazonka.Core as Core
import Amazonka.IoT.Types.Action
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Describes a rule.
--
-- /See:/ 'newTopicRulePayload' smart constructor.
data TopicRulePayload = TopicRulePayload'
  { -- | The version of the SQL rules engine to use when evaluating the rule.
    TopicRulePayload -> Maybe Text
awsIotSqlVersion :: Prelude.Maybe Prelude.Text,
    -- | The action to take when an error occurs.
    TopicRulePayload -> Maybe Action
errorAction :: Prelude.Maybe Action,
    -- | Specifies whether the rule is disabled.
    TopicRulePayload -> Maybe Bool
ruleDisabled :: Prelude.Maybe Prelude.Bool,
    -- | The description of the rule.
    TopicRulePayload -> Maybe Text
description :: Prelude.Maybe Prelude.Text,
    -- | The SQL statement used to query the topic. For more information, see
    -- <https://docs.aws.amazon.com/iot/latest/developerguide/iot-sql-reference.html IoT SQL Reference>
    -- in the /IoT Developer Guide/.
    TopicRulePayload -> Text
sql :: Prelude.Text,
    -- | The actions associated with the rule.
    TopicRulePayload -> [Action]
actions :: [Action]
  }
  deriving (TopicRulePayload -> TopicRulePayload -> Bool
(TopicRulePayload -> TopicRulePayload -> Bool)
-> (TopicRulePayload -> TopicRulePayload -> Bool)
-> Eq TopicRulePayload
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TopicRulePayload -> TopicRulePayload -> Bool
$c/= :: TopicRulePayload -> TopicRulePayload -> Bool
== :: TopicRulePayload -> TopicRulePayload -> Bool
$c== :: TopicRulePayload -> TopicRulePayload -> Bool
Prelude.Eq, ReadPrec [TopicRulePayload]
ReadPrec TopicRulePayload
Int -> ReadS TopicRulePayload
ReadS [TopicRulePayload]
(Int -> ReadS TopicRulePayload)
-> ReadS [TopicRulePayload]
-> ReadPrec TopicRulePayload
-> ReadPrec [TopicRulePayload]
-> Read TopicRulePayload
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TopicRulePayload]
$creadListPrec :: ReadPrec [TopicRulePayload]
readPrec :: ReadPrec TopicRulePayload
$creadPrec :: ReadPrec TopicRulePayload
readList :: ReadS [TopicRulePayload]
$creadList :: ReadS [TopicRulePayload]
readsPrec :: Int -> ReadS TopicRulePayload
$creadsPrec :: Int -> ReadS TopicRulePayload
Prelude.Read, Int -> TopicRulePayload -> ShowS
[TopicRulePayload] -> ShowS
TopicRulePayload -> String
(Int -> TopicRulePayload -> ShowS)
-> (TopicRulePayload -> String)
-> ([TopicRulePayload] -> ShowS)
-> Show TopicRulePayload
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TopicRulePayload] -> ShowS
$cshowList :: [TopicRulePayload] -> ShowS
show :: TopicRulePayload -> String
$cshow :: TopicRulePayload -> String
showsPrec :: Int -> TopicRulePayload -> ShowS
$cshowsPrec :: Int -> TopicRulePayload -> ShowS
Prelude.Show, (forall x. TopicRulePayload -> Rep TopicRulePayload x)
-> (forall x. Rep TopicRulePayload x -> TopicRulePayload)
-> Generic TopicRulePayload
forall x. Rep TopicRulePayload x -> TopicRulePayload
forall x. TopicRulePayload -> Rep TopicRulePayload x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TopicRulePayload x -> TopicRulePayload
$cfrom :: forall x. TopicRulePayload -> Rep TopicRulePayload x
Prelude.Generic)

-- |
-- Create a value of 'TopicRulePayload' 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:
--
-- 'awsIotSqlVersion', 'topicRulePayload_awsIotSqlVersion' - The version of the SQL rules engine to use when evaluating the rule.
--
-- 'errorAction', 'topicRulePayload_errorAction' - The action to take when an error occurs.
--
-- 'ruleDisabled', 'topicRulePayload_ruleDisabled' - Specifies whether the rule is disabled.
--
-- 'description', 'topicRulePayload_description' - The description of the rule.
--
-- 'sql', 'topicRulePayload_sql' - The SQL statement used to query the topic. For more information, see
-- <https://docs.aws.amazon.com/iot/latest/developerguide/iot-sql-reference.html IoT SQL Reference>
-- in the /IoT Developer Guide/.
--
-- 'actions', 'topicRulePayload_actions' - The actions associated with the rule.
newTopicRulePayload ::
  -- | 'sql'
  Prelude.Text ->
  TopicRulePayload
newTopicRulePayload :: Text -> TopicRulePayload
newTopicRulePayload Text
pSql_ =
  TopicRulePayload' :: Maybe Text
-> Maybe Action
-> Maybe Bool
-> Maybe Text
-> Text
-> [Action]
-> TopicRulePayload
TopicRulePayload'
    { $sel:awsIotSqlVersion:TopicRulePayload' :: Maybe Text
awsIotSqlVersion =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:errorAction:TopicRulePayload' :: Maybe Action
errorAction = Maybe Action
forall a. Maybe a
Prelude.Nothing,
      $sel:ruleDisabled:TopicRulePayload' :: Maybe Bool
ruleDisabled = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:description:TopicRulePayload' :: Maybe Text
description = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:sql:TopicRulePayload' :: Text
sql = Text
pSql_,
      $sel:actions:TopicRulePayload' :: [Action]
actions = [Action]
forall a. Monoid a => a
Prelude.mempty
    }

-- | The version of the SQL rules engine to use when evaluating the rule.
topicRulePayload_awsIotSqlVersion :: Lens.Lens' TopicRulePayload (Prelude.Maybe Prelude.Text)
topicRulePayload_awsIotSqlVersion :: (Maybe Text -> f (Maybe Text))
-> TopicRulePayload -> f TopicRulePayload
topicRulePayload_awsIotSqlVersion = (TopicRulePayload -> Maybe Text)
-> (TopicRulePayload -> Maybe Text -> TopicRulePayload)
-> Lens TopicRulePayload TopicRulePayload (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TopicRulePayload' {Maybe Text
awsIotSqlVersion :: Maybe Text
$sel:awsIotSqlVersion:TopicRulePayload' :: TopicRulePayload -> Maybe Text
awsIotSqlVersion} -> Maybe Text
awsIotSqlVersion) (\s :: TopicRulePayload
s@TopicRulePayload' {} Maybe Text
a -> TopicRulePayload
s {$sel:awsIotSqlVersion:TopicRulePayload' :: Maybe Text
awsIotSqlVersion = Maybe Text
a} :: TopicRulePayload)

-- | The action to take when an error occurs.
topicRulePayload_errorAction :: Lens.Lens' TopicRulePayload (Prelude.Maybe Action)
topicRulePayload_errorAction :: (Maybe Action -> f (Maybe Action))
-> TopicRulePayload -> f TopicRulePayload
topicRulePayload_errorAction = (TopicRulePayload -> Maybe Action)
-> (TopicRulePayload -> Maybe Action -> TopicRulePayload)
-> Lens
     TopicRulePayload TopicRulePayload (Maybe Action) (Maybe Action)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TopicRulePayload' {Maybe Action
errorAction :: Maybe Action
$sel:errorAction:TopicRulePayload' :: TopicRulePayload -> Maybe Action
errorAction} -> Maybe Action
errorAction) (\s :: TopicRulePayload
s@TopicRulePayload' {} Maybe Action
a -> TopicRulePayload
s {$sel:errorAction:TopicRulePayload' :: Maybe Action
errorAction = Maybe Action
a} :: TopicRulePayload)

-- | Specifies whether the rule is disabled.
topicRulePayload_ruleDisabled :: Lens.Lens' TopicRulePayload (Prelude.Maybe Prelude.Bool)
topicRulePayload_ruleDisabled :: (Maybe Bool -> f (Maybe Bool))
-> TopicRulePayload -> f TopicRulePayload
topicRulePayload_ruleDisabled = (TopicRulePayload -> Maybe Bool)
-> (TopicRulePayload -> Maybe Bool -> TopicRulePayload)
-> Lens TopicRulePayload TopicRulePayload (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TopicRulePayload' {Maybe Bool
ruleDisabled :: Maybe Bool
$sel:ruleDisabled:TopicRulePayload' :: TopicRulePayload -> Maybe Bool
ruleDisabled} -> Maybe Bool
ruleDisabled) (\s :: TopicRulePayload
s@TopicRulePayload' {} Maybe Bool
a -> TopicRulePayload
s {$sel:ruleDisabled:TopicRulePayload' :: Maybe Bool
ruleDisabled = Maybe Bool
a} :: TopicRulePayload)

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

-- | The SQL statement used to query the topic. For more information, see
-- <https://docs.aws.amazon.com/iot/latest/developerguide/iot-sql-reference.html IoT SQL Reference>
-- in the /IoT Developer Guide/.
topicRulePayload_sql :: Lens.Lens' TopicRulePayload Prelude.Text
topicRulePayload_sql :: (Text -> f Text) -> TopicRulePayload -> f TopicRulePayload
topicRulePayload_sql = (TopicRulePayload -> Text)
-> (TopicRulePayload -> Text -> TopicRulePayload)
-> Lens TopicRulePayload TopicRulePayload Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TopicRulePayload' {Text
sql :: Text
$sel:sql:TopicRulePayload' :: TopicRulePayload -> Text
sql} -> Text
sql) (\s :: TopicRulePayload
s@TopicRulePayload' {} Text
a -> TopicRulePayload
s {$sel:sql:TopicRulePayload' :: Text
sql = Text
a} :: TopicRulePayload)

-- | The actions associated with the rule.
topicRulePayload_actions :: Lens.Lens' TopicRulePayload [Action]
topicRulePayload_actions :: ([Action] -> f [Action]) -> TopicRulePayload -> f TopicRulePayload
topicRulePayload_actions = (TopicRulePayload -> [Action])
-> (TopicRulePayload -> [Action] -> TopicRulePayload)
-> Lens TopicRulePayload TopicRulePayload [Action] [Action]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TopicRulePayload' {[Action]
actions :: [Action]
$sel:actions:TopicRulePayload' :: TopicRulePayload -> [Action]
actions} -> [Action]
actions) (\s :: TopicRulePayload
s@TopicRulePayload' {} [Action]
a -> TopicRulePayload
s {$sel:actions:TopicRulePayload' :: [Action]
actions = [Action]
a} :: TopicRulePayload) (([Action] -> f [Action])
 -> TopicRulePayload -> f TopicRulePayload)
-> (([Action] -> f [Action]) -> [Action] -> f [Action])
-> ([Action] -> f [Action])
-> TopicRulePayload
-> f TopicRulePayload
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Action] -> f [Action]) -> [Action] -> f [Action]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Prelude.Hashable TopicRulePayload

instance Prelude.NFData TopicRulePayload

instance Core.ToJSON TopicRulePayload where
  toJSON :: TopicRulePayload -> Value
toJSON TopicRulePayload' {[Action]
Maybe Bool
Maybe Text
Maybe Action
Text
actions :: [Action]
sql :: Text
description :: Maybe Text
ruleDisabled :: Maybe Bool
errorAction :: Maybe Action
awsIotSqlVersion :: Maybe Text
$sel:actions:TopicRulePayload' :: TopicRulePayload -> [Action]
$sel:sql:TopicRulePayload' :: TopicRulePayload -> Text
$sel:description:TopicRulePayload' :: TopicRulePayload -> Maybe Text
$sel:ruleDisabled:TopicRulePayload' :: TopicRulePayload -> Maybe Bool
$sel:errorAction:TopicRulePayload' :: TopicRulePayload -> Maybe Action
$sel:awsIotSqlVersion:TopicRulePayload' :: TopicRulePayload -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"awsIotSqlVersion" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
awsIotSqlVersion,
            (Text
"errorAction" Text -> Action -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Action -> Pair) -> Maybe Action -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Action
errorAction,
            (Text
"ruleDisabled" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
ruleDisabled,
            (Text
"description" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
description,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"sql" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
sql),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"actions" Text -> [Action] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [Action]
actions)
          ]
      )