{-# 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.TopicRule
-- 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.TopicRule 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:/ 'newTopicRule' smart constructor.
data TopicRule = TopicRule'
  { -- | The date and time the rule was created.
    TopicRule -> Maybe POSIX
createdAt :: Prelude.Maybe Core.POSIX,
    -- | The actions associated with the rule.
    TopicRule -> Maybe [Action]
actions :: Prelude.Maybe [Action],
    -- | The version of the SQL rules engine to use when evaluating the rule.
    TopicRule -> Maybe Text
awsIotSqlVersion :: Prelude.Maybe Prelude.Text,
    -- | The action to perform when an error occurs.
    TopicRule -> Maybe Action
errorAction :: Prelude.Maybe Action,
    -- | Specifies whether the rule is disabled.
    TopicRule -> Maybe Bool
ruleDisabled :: Prelude.Maybe Prelude.Bool,
    -- | The name of the rule.
    TopicRule -> Maybe Text
ruleName :: Prelude.Maybe Prelude.Text,
    -- | The SQL statement used to query the topic. When using a SQL query with
    -- multiple lines, be sure to escape the newline characters.
    TopicRule -> Maybe Text
sql :: Prelude.Maybe Prelude.Text,
    -- | The description of the rule.
    TopicRule -> Maybe Text
description :: Prelude.Maybe Prelude.Text
  }
  deriving (TopicRule -> TopicRule -> Bool
(TopicRule -> TopicRule -> Bool)
-> (TopicRule -> TopicRule -> Bool) -> Eq TopicRule
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TopicRule -> TopicRule -> Bool
$c/= :: TopicRule -> TopicRule -> Bool
== :: TopicRule -> TopicRule -> Bool
$c== :: TopicRule -> TopicRule -> Bool
Prelude.Eq, ReadPrec [TopicRule]
ReadPrec TopicRule
Int -> ReadS TopicRule
ReadS [TopicRule]
(Int -> ReadS TopicRule)
-> ReadS [TopicRule]
-> ReadPrec TopicRule
-> ReadPrec [TopicRule]
-> Read TopicRule
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TopicRule]
$creadListPrec :: ReadPrec [TopicRule]
readPrec :: ReadPrec TopicRule
$creadPrec :: ReadPrec TopicRule
readList :: ReadS [TopicRule]
$creadList :: ReadS [TopicRule]
readsPrec :: Int -> ReadS TopicRule
$creadsPrec :: Int -> ReadS TopicRule
Prelude.Read, Int -> TopicRule -> ShowS
[TopicRule] -> ShowS
TopicRule -> String
(Int -> TopicRule -> ShowS)
-> (TopicRule -> String)
-> ([TopicRule] -> ShowS)
-> Show TopicRule
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TopicRule] -> ShowS
$cshowList :: [TopicRule] -> ShowS
show :: TopicRule -> String
$cshow :: TopicRule -> String
showsPrec :: Int -> TopicRule -> ShowS
$cshowsPrec :: Int -> TopicRule -> ShowS
Prelude.Show, (forall x. TopicRule -> Rep TopicRule x)
-> (forall x. Rep TopicRule x -> TopicRule) -> Generic TopicRule
forall x. Rep TopicRule x -> TopicRule
forall x. TopicRule -> Rep TopicRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TopicRule x -> TopicRule
$cfrom :: forall x. TopicRule -> Rep TopicRule x
Prelude.Generic)

-- |
-- Create a value of 'TopicRule' 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:
--
-- 'createdAt', 'topicRule_createdAt' - The date and time the rule was created.
--
-- 'actions', 'topicRule_actions' - The actions associated with the rule.
--
-- 'awsIotSqlVersion', 'topicRule_awsIotSqlVersion' - The version of the SQL rules engine to use when evaluating the rule.
--
-- 'errorAction', 'topicRule_errorAction' - The action to perform when an error occurs.
--
-- 'ruleDisabled', 'topicRule_ruleDisabled' - Specifies whether the rule is disabled.
--
-- 'ruleName', 'topicRule_ruleName' - The name of the rule.
--
-- 'sql', 'topicRule_sql' - The SQL statement used to query the topic. When using a SQL query with
-- multiple lines, be sure to escape the newline characters.
--
-- 'description', 'topicRule_description' - The description of the rule.
newTopicRule ::
  TopicRule
newTopicRule :: TopicRule
newTopicRule =
  TopicRule' :: Maybe POSIX
-> Maybe [Action]
-> Maybe Text
-> Maybe Action
-> Maybe Bool
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> TopicRule
TopicRule'
    { $sel:createdAt:TopicRule' :: Maybe POSIX
createdAt = Maybe POSIX
forall a. Maybe a
Prelude.Nothing,
      $sel:actions:TopicRule' :: Maybe [Action]
actions = Maybe [Action]
forall a. Maybe a
Prelude.Nothing,
      $sel:awsIotSqlVersion:TopicRule' :: Maybe Text
awsIotSqlVersion = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:errorAction:TopicRule' :: Maybe Action
errorAction = Maybe Action
forall a. Maybe a
Prelude.Nothing,
      $sel:ruleDisabled:TopicRule' :: Maybe Bool
ruleDisabled = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:ruleName:TopicRule' :: Maybe Text
ruleName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:sql:TopicRule' :: Maybe Text
sql = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:description:TopicRule' :: Maybe Text
description = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The date and time the rule was created.
topicRule_createdAt :: Lens.Lens' TopicRule (Prelude.Maybe Prelude.UTCTime)
topicRule_createdAt :: (Maybe UTCTime -> f (Maybe UTCTime)) -> TopicRule -> f TopicRule
topicRule_createdAt = (TopicRule -> Maybe POSIX)
-> (TopicRule -> Maybe POSIX -> TopicRule)
-> Lens TopicRule TopicRule (Maybe POSIX) (Maybe POSIX)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TopicRule' {Maybe POSIX
createdAt :: Maybe POSIX
$sel:createdAt:TopicRule' :: TopicRule -> Maybe POSIX
createdAt} -> Maybe POSIX
createdAt) (\s :: TopicRule
s@TopicRule' {} Maybe POSIX
a -> TopicRule
s {$sel:createdAt:TopicRule' :: Maybe POSIX
createdAt = Maybe POSIX
a} :: TopicRule) ((Maybe POSIX -> f (Maybe POSIX)) -> TopicRule -> f TopicRule)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> TopicRule
-> f TopicRule
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso POSIX POSIX UTCTime UTCTime
-> Iso (Maybe POSIX) (Maybe POSIX) (Maybe UTCTime) (Maybe UTCTime)
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso POSIX POSIX UTCTime UTCTime
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

-- | The actions associated with the rule.
topicRule_actions :: Lens.Lens' TopicRule (Prelude.Maybe [Action])
topicRule_actions :: (Maybe [Action] -> f (Maybe [Action])) -> TopicRule -> f TopicRule
topicRule_actions = (TopicRule -> Maybe [Action])
-> (TopicRule -> Maybe [Action] -> TopicRule)
-> Lens TopicRule TopicRule (Maybe [Action]) (Maybe [Action])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TopicRule' {Maybe [Action]
actions :: Maybe [Action]
$sel:actions:TopicRule' :: TopicRule -> Maybe [Action]
actions} -> Maybe [Action]
actions) (\s :: TopicRule
s@TopicRule' {} Maybe [Action]
a -> TopicRule
s {$sel:actions:TopicRule' :: Maybe [Action]
actions = Maybe [Action]
a} :: TopicRule) ((Maybe [Action] -> f (Maybe [Action]))
 -> TopicRule -> f TopicRule)
-> ((Maybe [Action] -> f (Maybe [Action]))
    -> Maybe [Action] -> f (Maybe [Action]))
-> (Maybe [Action] -> f (Maybe [Action]))
-> TopicRule
-> f TopicRule
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Action] [Action] [Action] [Action]
-> Iso
     (Maybe [Action]) (Maybe [Action]) (Maybe [Action]) (Maybe [Action])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso [Action] [Action] [Action] [Action]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

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

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

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

-- | The SQL statement used to query the topic. When using a SQL query with
-- multiple lines, be sure to escape the newline characters.
topicRule_sql :: Lens.Lens' TopicRule (Prelude.Maybe Prelude.Text)
topicRule_sql :: (Maybe Text -> f (Maybe Text)) -> TopicRule -> f TopicRule
topicRule_sql = (TopicRule -> Maybe Text)
-> (TopicRule -> Maybe Text -> TopicRule)
-> Lens TopicRule TopicRule (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TopicRule' {Maybe Text
sql :: Maybe Text
$sel:sql:TopicRule' :: TopicRule -> Maybe Text
sql} -> Maybe Text
sql) (\s :: TopicRule
s@TopicRule' {} Maybe Text
a -> TopicRule
s {$sel:sql:TopicRule' :: Maybe Text
sql = Maybe Text
a} :: TopicRule)

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

instance Core.FromJSON TopicRule where
  parseJSON :: Value -> Parser TopicRule
parseJSON =
    String -> (Object -> Parser TopicRule) -> Value -> Parser TopicRule
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"TopicRule"
      ( \Object
x ->
          Maybe POSIX
-> Maybe [Action]
-> Maybe Text
-> Maybe Action
-> Maybe Bool
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> TopicRule
TopicRule'
            (Maybe POSIX
 -> Maybe [Action]
 -> Maybe Text
 -> Maybe Action
 -> Maybe Bool
 -> Maybe Text
 -> Maybe Text
 -> Maybe Text
 -> TopicRule)
-> Parser (Maybe POSIX)
-> Parser
     (Maybe [Action]
      -> Maybe Text
      -> Maybe Action
      -> Maybe Bool
      -> Maybe Text
      -> Maybe Text
      -> Maybe Text
      -> TopicRule)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe POSIX)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"createdAt")
            Parser
  (Maybe [Action]
   -> Maybe Text
   -> Maybe Action
   -> Maybe Bool
   -> Maybe Text
   -> Maybe Text
   -> Maybe Text
   -> TopicRule)
-> Parser (Maybe [Action])
-> Parser
     (Maybe Text
      -> Maybe Action
      -> Maybe Bool
      -> Maybe Text
      -> Maybe Text
      -> Maybe Text
      -> TopicRule)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Maybe [Action]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"actions" Parser (Maybe (Maybe [Action]))
-> Maybe [Action] -> Parser (Maybe [Action])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [Action]
forall a. Monoid a => a
Prelude.mempty)
            Parser
  (Maybe Text
   -> Maybe Action
   -> Maybe Bool
   -> Maybe Text
   -> Maybe Text
   -> Maybe Text
   -> TopicRule)
-> Parser (Maybe Text)
-> Parser
     (Maybe Action
      -> Maybe Bool
      -> Maybe Text
      -> Maybe Text
      -> Maybe Text
      -> TopicRule)
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
"awsIotSqlVersion")
            Parser
  (Maybe Action
   -> Maybe Bool
   -> Maybe Text
   -> Maybe Text
   -> Maybe Text
   -> TopicRule)
-> Parser (Maybe Action)
-> Parser
     (Maybe Bool -> Maybe Text -> Maybe Text -> Maybe Text -> TopicRule)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Action)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"errorAction")
            Parser
  (Maybe Bool -> Maybe Text -> Maybe Text -> Maybe Text -> TopicRule)
-> Parser (Maybe Bool)
-> Parser (Maybe Text -> Maybe Text -> Maybe Text -> TopicRule)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ruleDisabled")
            Parser (Maybe Text -> Maybe Text -> Maybe Text -> TopicRule)
-> Parser (Maybe Text)
-> Parser (Maybe Text -> Maybe Text -> TopicRule)
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
"ruleName")
            Parser (Maybe Text -> Maybe Text -> TopicRule)
-> Parser (Maybe Text) -> Parser (Maybe Text -> TopicRule)
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
"sql")
            Parser (Maybe Text -> TopicRule)
-> Parser (Maybe Text) -> Parser TopicRule
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")
      )

instance Prelude.Hashable TopicRule

instance Prelude.NFData TopicRule