{-# 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.IoTSiteWise.Types.PropertyNotification
-- 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.IoTSiteWise.Types.PropertyNotification where

import qualified Amazonka.Core as Core
import Amazonka.IoTSiteWise.Types.PropertyNotificationState
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Contains asset property value notification information. When the
-- notification state is enabled, IoT SiteWise publishes property value
-- updates to a unique MQTT topic. For more information, see
-- <https://docs.aws.amazon.com/iot-sitewise/latest/userguide/interact-with-other-services.html Interacting with other services>
-- in the /IoT SiteWise User Guide/.
--
-- /See:/ 'newPropertyNotification' smart constructor.
data PropertyNotification = PropertyNotification'
  { -- | The MQTT topic to which IoT SiteWise publishes property value update
    -- notifications.
    PropertyNotification -> Text
topic :: Prelude.Text,
    -- | The current notification state.
    PropertyNotification -> PropertyNotificationState
state :: PropertyNotificationState
  }
  deriving (PropertyNotification -> PropertyNotification -> Bool
(PropertyNotification -> PropertyNotification -> Bool)
-> (PropertyNotification -> PropertyNotification -> Bool)
-> Eq PropertyNotification
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PropertyNotification -> PropertyNotification -> Bool
$c/= :: PropertyNotification -> PropertyNotification -> Bool
== :: PropertyNotification -> PropertyNotification -> Bool
$c== :: PropertyNotification -> PropertyNotification -> Bool
Prelude.Eq, ReadPrec [PropertyNotification]
ReadPrec PropertyNotification
Int -> ReadS PropertyNotification
ReadS [PropertyNotification]
(Int -> ReadS PropertyNotification)
-> ReadS [PropertyNotification]
-> ReadPrec PropertyNotification
-> ReadPrec [PropertyNotification]
-> Read PropertyNotification
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PropertyNotification]
$creadListPrec :: ReadPrec [PropertyNotification]
readPrec :: ReadPrec PropertyNotification
$creadPrec :: ReadPrec PropertyNotification
readList :: ReadS [PropertyNotification]
$creadList :: ReadS [PropertyNotification]
readsPrec :: Int -> ReadS PropertyNotification
$creadsPrec :: Int -> ReadS PropertyNotification
Prelude.Read, Int -> PropertyNotification -> ShowS
[PropertyNotification] -> ShowS
PropertyNotification -> String
(Int -> PropertyNotification -> ShowS)
-> (PropertyNotification -> String)
-> ([PropertyNotification] -> ShowS)
-> Show PropertyNotification
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PropertyNotification] -> ShowS
$cshowList :: [PropertyNotification] -> ShowS
show :: PropertyNotification -> String
$cshow :: PropertyNotification -> String
showsPrec :: Int -> PropertyNotification -> ShowS
$cshowsPrec :: Int -> PropertyNotification -> ShowS
Prelude.Show, (forall x. PropertyNotification -> Rep PropertyNotification x)
-> (forall x. Rep PropertyNotification x -> PropertyNotification)
-> Generic PropertyNotification
forall x. Rep PropertyNotification x -> PropertyNotification
forall x. PropertyNotification -> Rep PropertyNotification x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PropertyNotification x -> PropertyNotification
$cfrom :: forall x. PropertyNotification -> Rep PropertyNotification x
Prelude.Generic)

-- |
-- Create a value of 'PropertyNotification' 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:
--
-- 'topic', 'propertyNotification_topic' - The MQTT topic to which IoT SiteWise publishes property value update
-- notifications.
--
-- 'state', 'propertyNotification_state' - The current notification state.
newPropertyNotification ::
  -- | 'topic'
  Prelude.Text ->
  -- | 'state'
  PropertyNotificationState ->
  PropertyNotification
newPropertyNotification :: Text -> PropertyNotificationState -> PropertyNotification
newPropertyNotification Text
pTopic_ PropertyNotificationState
pState_ =
  PropertyNotification' :: Text -> PropertyNotificationState -> PropertyNotification
PropertyNotification'
    { $sel:topic:PropertyNotification' :: Text
topic = Text
pTopic_,
      $sel:state:PropertyNotification' :: PropertyNotificationState
state = PropertyNotificationState
pState_
    }

-- | The MQTT topic to which IoT SiteWise publishes property value update
-- notifications.
propertyNotification_topic :: Lens.Lens' PropertyNotification Prelude.Text
propertyNotification_topic :: (Text -> f Text) -> PropertyNotification -> f PropertyNotification
propertyNotification_topic = (PropertyNotification -> Text)
-> (PropertyNotification -> Text -> PropertyNotification)
-> Lens PropertyNotification PropertyNotification Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PropertyNotification' {Text
topic :: Text
$sel:topic:PropertyNotification' :: PropertyNotification -> Text
topic} -> Text
topic) (\s :: PropertyNotification
s@PropertyNotification' {} Text
a -> PropertyNotification
s {$sel:topic:PropertyNotification' :: Text
topic = Text
a} :: PropertyNotification)

-- | The current notification state.
propertyNotification_state :: Lens.Lens' PropertyNotification PropertyNotificationState
propertyNotification_state :: (PropertyNotificationState -> f PropertyNotificationState)
-> PropertyNotification -> f PropertyNotification
propertyNotification_state = (PropertyNotification -> PropertyNotificationState)
-> (PropertyNotification
    -> PropertyNotificationState -> PropertyNotification)
-> Lens
     PropertyNotification
     PropertyNotification
     PropertyNotificationState
     PropertyNotificationState
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PropertyNotification' {PropertyNotificationState
state :: PropertyNotificationState
$sel:state:PropertyNotification' :: PropertyNotification -> PropertyNotificationState
state} -> PropertyNotificationState
state) (\s :: PropertyNotification
s@PropertyNotification' {} PropertyNotificationState
a -> PropertyNotification
s {$sel:state:PropertyNotification' :: PropertyNotificationState
state = PropertyNotificationState
a} :: PropertyNotification)

instance Core.FromJSON PropertyNotification where
  parseJSON :: Value -> Parser PropertyNotification
parseJSON =
    String
-> (Object -> Parser PropertyNotification)
-> Value
-> Parser PropertyNotification
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"PropertyNotification"
      ( \Object
x ->
          Text -> PropertyNotificationState -> PropertyNotification
PropertyNotification'
            (Text -> PropertyNotificationState -> PropertyNotification)
-> Parser Text
-> Parser (PropertyNotificationState -> PropertyNotification)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"topic") Parser (PropertyNotificationState -> PropertyNotification)
-> Parser PropertyNotificationState -> Parser PropertyNotification
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser PropertyNotificationState
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"state")
      )

instance Prelude.Hashable PropertyNotification

instance Prelude.NFData PropertyNotification