{-# 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-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.TopicRule 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:/ 'newTopicRule' smart constructor.
data TopicRule = TopicRule'
  { -- | 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 date and time the rule was created.
    TopicRule -> Maybe POSIX
createdAt :: Prelude.Maybe Data.POSIX,
    -- | The description of the rule.
    TopicRule -> Maybe Text
description :: 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
  }
  deriving (TopicRule -> TopicRule -> Bool
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]
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
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. 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:
--
-- '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.
--
-- 'createdAt', 'topicRule_createdAt' - The date and time the rule was created.
--
-- 'description', 'topicRule_description' - The description of 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.
newTopicRule ::
  TopicRule
newTopicRule :: TopicRule
newTopicRule =
  TopicRule'
    { $sel:actions:TopicRule' :: Maybe [Action]
actions = forall a. Maybe a
Prelude.Nothing,
      $sel:awsIotSqlVersion:TopicRule' :: Maybe Text
awsIotSqlVersion = forall a. Maybe a
Prelude.Nothing,
      $sel:createdAt:TopicRule' :: Maybe POSIX
createdAt = forall a. Maybe a
Prelude.Nothing,
      $sel:description:TopicRule' :: Maybe Text
description = forall a. Maybe a
Prelude.Nothing,
      $sel:errorAction:TopicRule' :: Maybe Action
errorAction = forall a. Maybe a
Prelude.Nothing,
      $sel:ruleDisabled:TopicRule' :: Maybe Bool
ruleDisabled = forall a. Maybe a
Prelude.Nothing,
      $sel:ruleName:TopicRule' :: Maybe Text
ruleName = forall a. Maybe a
Prelude.Nothing,
      $sel:sql:TopicRule' :: Maybe Text
sql = forall a. Maybe a
Prelude.Nothing
    }

-- | The actions associated with the rule.
topicRule_actions :: Lens.Lens' TopicRule (Prelude.Maybe [Action])
topicRule_actions :: Lens' TopicRule (Maybe [Action])
topicRule_actions = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 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 :: Lens' TopicRule (Maybe Text)
topicRule_awsIotSqlVersion = 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 date and time the rule was created.
topicRule_createdAt :: Lens.Lens' TopicRule (Prelude.Maybe Prelude.UTCTime)
topicRule_createdAt :: Lens' TopicRule (Maybe UTCTime)
topicRule_createdAt = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall (a :: Format). Iso' (Time a) UTCTime
Data._Time

-- | The description of the rule.
topicRule_description :: Lens.Lens' TopicRule (Prelude.Maybe Prelude.Text)
topicRule_description :: Lens' TopicRule (Maybe Text)
topicRule_description = 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)

-- | The action to perform when an error occurs.
topicRule_errorAction :: Lens.Lens' TopicRule (Prelude.Maybe Action)
topicRule_errorAction :: Lens' TopicRule (Maybe Action)
topicRule_errorAction = 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 :: Lens' TopicRule (Maybe Bool)
topicRule_ruleDisabled = 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 :: Lens' TopicRule (Maybe Text)
topicRule_ruleName = 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 :: Lens' TopicRule (Maybe Text)
topicRule_sql = 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)

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

instance Prelude.Hashable TopicRule where
  hashWithSalt :: Int -> TopicRule -> Int
hashWithSalt Int
_salt TopicRule' {Maybe Bool
Maybe [Action]
Maybe Text
Maybe POSIX
Maybe Action
sql :: Maybe Text
ruleName :: Maybe Text
ruleDisabled :: Maybe Bool
errorAction :: Maybe Action
description :: Maybe Text
createdAt :: Maybe POSIX
awsIotSqlVersion :: Maybe Text
actions :: Maybe [Action]
$sel:sql:TopicRule' :: TopicRule -> Maybe Text
$sel:ruleName:TopicRule' :: TopicRule -> Maybe Text
$sel:ruleDisabled:TopicRule' :: TopicRule -> Maybe Bool
$sel:errorAction:TopicRule' :: TopicRule -> Maybe Action
$sel:description:TopicRule' :: TopicRule -> Maybe Text
$sel:createdAt:TopicRule' :: TopicRule -> Maybe POSIX
$sel:awsIotSqlVersion:TopicRule' :: TopicRule -> Maybe Text
$sel:actions:TopicRule' :: TopicRule -> Maybe [Action]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Action]
actions
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
awsIotSqlVersion
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe POSIX
createdAt
      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` Maybe Text
ruleName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
sql

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