{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.IoT.Types.TopicRulePayload where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.IoT.Types.Action
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 description of the rule.
    TopicRulePayload -> Maybe Text
description :: 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 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
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]
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
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. 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.
--
-- 'description', 'topicRulePayload_description' - The description of the rule.
--
-- 'errorAction', 'topicRulePayload_errorAction' - The action to take when an error occurs.
--
-- 'ruleDisabled', 'topicRulePayload_ruleDisabled' - Specifies whether the rule is disabled.
--
-- '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'
    { $sel:awsIotSqlVersion:TopicRulePayload' :: Maybe Text
awsIotSqlVersion =
        forall a. Maybe a
Prelude.Nothing,
      $sel:description:TopicRulePayload' :: Maybe Text
description = forall a. Maybe a
Prelude.Nothing,
      $sel:errorAction:TopicRulePayload' :: Maybe Action
errorAction = forall a. Maybe a
Prelude.Nothing,
      $sel:ruleDisabled:TopicRulePayload' :: Maybe Bool
ruleDisabled = forall a. Maybe a
Prelude.Nothing,
      $sel:sql:TopicRulePayload' :: Text
sql = Text
pSql_,
      $sel:actions:TopicRulePayload' :: [Action]
actions = 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 :: Lens' TopicRulePayload (Maybe Text)
topicRulePayload_awsIotSqlVersion = 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 description of the rule.
topicRulePayload_description :: Lens.Lens' TopicRulePayload (Prelude.Maybe Prelude.Text)
topicRulePayload_description :: Lens' TopicRulePayload (Maybe Text)
topicRulePayload_description = 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 action to take when an error occurs.
topicRulePayload_errorAction :: Lens.Lens' TopicRulePayload (Prelude.Maybe Action)
topicRulePayload_errorAction :: Lens' TopicRulePayload (Maybe Action)
topicRulePayload_errorAction = 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 :: Lens' TopicRulePayload (Maybe Bool)
topicRulePayload_ruleDisabled = 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 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 :: Lens' TopicRulePayload Text
topicRulePayload_sql = 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 :: Lens' TopicRulePayload [Action]
topicRulePayload_actions = 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) 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 Prelude.Hashable TopicRulePayload where
  hashWithSalt :: Int -> TopicRulePayload -> Int
hashWithSalt Int
_salt TopicRulePayload' {[Action]
Maybe Bool
Maybe Text
Maybe Action
Text
actions :: [Action]
sql :: Text
ruleDisabled :: Maybe Bool
errorAction :: Maybe Action
description :: Maybe Text
awsIotSqlVersion :: Maybe Text
$sel:actions:TopicRulePayload' :: TopicRulePayload -> [Action]
$sel:sql:TopicRulePayload' :: TopicRulePayload -> Text
$sel:ruleDisabled:TopicRulePayload' :: TopicRulePayload -> Maybe Bool
$sel:errorAction:TopicRulePayload' :: TopicRulePayload -> Maybe Action
$sel:description:TopicRulePayload' :: TopicRulePayload -> Maybe Text
$sel:awsIotSqlVersion:TopicRulePayload' :: TopicRulePayload -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
awsIotSqlVersion
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
description
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Action
errorAction
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
ruleDisabled
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
sql
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [Action]
actions

instance Prelude.NFData TopicRulePayload where
  rnf :: TopicRulePayload -> ()
rnf TopicRulePayload' {[Action]
Maybe Bool
Maybe Text
Maybe Action
Text
actions :: [Action]
sql :: Text
ruleDisabled :: Maybe Bool
errorAction :: Maybe Action
description :: Maybe Text
awsIotSqlVersion :: Maybe Text
$sel:actions:TopicRulePayload' :: TopicRulePayload -> [Action]
$sel:sql:TopicRulePayload' :: TopicRulePayload -> Text
$sel:ruleDisabled:TopicRulePayload' :: TopicRulePayload -> Maybe Bool
$sel:errorAction:TopicRulePayload' :: TopicRulePayload -> Maybe Action
$sel:description:TopicRulePayload' :: TopicRulePayload -> Maybe Text
$sel:awsIotSqlVersion:TopicRulePayload' :: TopicRulePayload -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
awsIotSqlVersion
      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 Action
errorAction
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
ruleDisabled
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
sql
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [Action]
actions

instance Data.ToJSON TopicRulePayload where
  toJSON :: TopicRulePayload -> Value
toJSON TopicRulePayload' {[Action]
Maybe Bool
Maybe Text
Maybe Action
Text
actions :: [Action]
sql :: Text
ruleDisabled :: Maybe Bool
errorAction :: Maybe Action
description :: Maybe Text
awsIotSqlVersion :: Maybe Text
$sel:actions:TopicRulePayload' :: TopicRulePayload -> [Action]
$sel:sql:TopicRulePayload' :: TopicRulePayload -> Text
$sel:ruleDisabled:TopicRulePayload' :: TopicRulePayload -> Maybe Bool
$sel:errorAction:TopicRulePayload' :: TopicRulePayload -> Maybe Action
$sel:description:TopicRulePayload' :: TopicRulePayload -> Maybe Text
$sel:awsIotSqlVersion:TopicRulePayload' :: TopicRulePayload -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"awsIotSqlVersion" 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
awsIotSqlVersion,
            (Key
"description" 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
description,
            (Key
"errorAction" 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 Action
errorAction,
            (Key
"ruleDisabled" 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
ruleDisabled,
            forall a. a -> Maybe a
Prelude.Just (Key
"sql" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
sql),
            forall a. a -> Maybe a
Prelude.Just (Key
"actions" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= [Action]
actions)
          ]
      )