{-# 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.IoT1ClickDevices.Types.DeviceEvent
-- 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.IoT1ClickDevices.Types.DeviceEvent where

import qualified Amazonka.Core as Core
import Amazonka.IoT1ClickDevices.Types.Device
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | /See:/ 'newDeviceEvent' smart constructor.
data DeviceEvent = DeviceEvent'
  { -- | A serialized JSON object representing the device-type specific event.
    DeviceEvent -> Maybe Text
stdEvent :: Prelude.Maybe Prelude.Text,
    -- | An object representing the device associated with the event.
    DeviceEvent -> Maybe Device
device :: Prelude.Maybe Device
  }
  deriving (DeviceEvent -> DeviceEvent -> Bool
(DeviceEvent -> DeviceEvent -> Bool)
-> (DeviceEvent -> DeviceEvent -> Bool) -> Eq DeviceEvent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeviceEvent -> DeviceEvent -> Bool
$c/= :: DeviceEvent -> DeviceEvent -> Bool
== :: DeviceEvent -> DeviceEvent -> Bool
$c== :: DeviceEvent -> DeviceEvent -> Bool
Prelude.Eq, ReadPrec [DeviceEvent]
ReadPrec DeviceEvent
Int -> ReadS DeviceEvent
ReadS [DeviceEvent]
(Int -> ReadS DeviceEvent)
-> ReadS [DeviceEvent]
-> ReadPrec DeviceEvent
-> ReadPrec [DeviceEvent]
-> Read DeviceEvent
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeviceEvent]
$creadListPrec :: ReadPrec [DeviceEvent]
readPrec :: ReadPrec DeviceEvent
$creadPrec :: ReadPrec DeviceEvent
readList :: ReadS [DeviceEvent]
$creadList :: ReadS [DeviceEvent]
readsPrec :: Int -> ReadS DeviceEvent
$creadsPrec :: Int -> ReadS DeviceEvent
Prelude.Read, Int -> DeviceEvent -> ShowS
[DeviceEvent] -> ShowS
DeviceEvent -> String
(Int -> DeviceEvent -> ShowS)
-> (DeviceEvent -> String)
-> ([DeviceEvent] -> ShowS)
-> Show DeviceEvent
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeviceEvent] -> ShowS
$cshowList :: [DeviceEvent] -> ShowS
show :: DeviceEvent -> String
$cshow :: DeviceEvent -> String
showsPrec :: Int -> DeviceEvent -> ShowS
$cshowsPrec :: Int -> DeviceEvent -> ShowS
Prelude.Show, (forall x. DeviceEvent -> Rep DeviceEvent x)
-> (forall x. Rep DeviceEvent x -> DeviceEvent)
-> Generic DeviceEvent
forall x. Rep DeviceEvent x -> DeviceEvent
forall x. DeviceEvent -> Rep DeviceEvent x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeviceEvent x -> DeviceEvent
$cfrom :: forall x. DeviceEvent -> Rep DeviceEvent x
Prelude.Generic)

-- |
-- Create a value of 'DeviceEvent' 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:
--
-- 'stdEvent', 'deviceEvent_stdEvent' - A serialized JSON object representing the device-type specific event.
--
-- 'device', 'deviceEvent_device' - An object representing the device associated with the event.
newDeviceEvent ::
  DeviceEvent
newDeviceEvent :: DeviceEvent
newDeviceEvent =
  DeviceEvent' :: Maybe Text -> Maybe Device -> DeviceEvent
DeviceEvent'
    { $sel:stdEvent:DeviceEvent' :: Maybe Text
stdEvent = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:device:DeviceEvent' :: Maybe Device
device = Maybe Device
forall a. Maybe a
Prelude.Nothing
    }

-- | A serialized JSON object representing the device-type specific event.
deviceEvent_stdEvent :: Lens.Lens' DeviceEvent (Prelude.Maybe Prelude.Text)
deviceEvent_stdEvent :: (Maybe Text -> f (Maybe Text)) -> DeviceEvent -> f DeviceEvent
deviceEvent_stdEvent = (DeviceEvent -> Maybe Text)
-> (DeviceEvent -> Maybe Text -> DeviceEvent)
-> Lens DeviceEvent DeviceEvent (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeviceEvent' {Maybe Text
stdEvent :: Maybe Text
$sel:stdEvent:DeviceEvent' :: DeviceEvent -> Maybe Text
stdEvent} -> Maybe Text
stdEvent) (\s :: DeviceEvent
s@DeviceEvent' {} Maybe Text
a -> DeviceEvent
s {$sel:stdEvent:DeviceEvent' :: Maybe Text
stdEvent = Maybe Text
a} :: DeviceEvent)

-- | An object representing the device associated with the event.
deviceEvent_device :: Lens.Lens' DeviceEvent (Prelude.Maybe Device)
deviceEvent_device :: (Maybe Device -> f (Maybe Device)) -> DeviceEvent -> f DeviceEvent
deviceEvent_device = (DeviceEvent -> Maybe Device)
-> (DeviceEvent -> Maybe Device -> DeviceEvent)
-> Lens DeviceEvent DeviceEvent (Maybe Device) (Maybe Device)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeviceEvent' {Maybe Device
device :: Maybe Device
$sel:device:DeviceEvent' :: DeviceEvent -> Maybe Device
device} -> Maybe Device
device) (\s :: DeviceEvent
s@DeviceEvent' {} Maybe Device
a -> DeviceEvent
s {$sel:device:DeviceEvent' :: Maybe Device
device = Maybe Device
a} :: DeviceEvent)

instance Core.FromJSON DeviceEvent where
  parseJSON :: Value -> Parser DeviceEvent
parseJSON =
    String
-> (Object -> Parser DeviceEvent) -> Value -> Parser DeviceEvent
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"DeviceEvent"
      ( \Object
x ->
          Maybe Text -> Maybe Device -> DeviceEvent
DeviceEvent'
            (Maybe Text -> Maybe Device -> DeviceEvent)
-> Parser (Maybe Text) -> Parser (Maybe Device -> DeviceEvent)
forall (f :: * -> *) a b. Functor 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
"stdEvent")
            Parser (Maybe Device -> DeviceEvent)
-> Parser (Maybe Device) -> Parser DeviceEvent
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Device)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"device")
      )

instance Prelude.Hashable DeviceEvent

instance Prelude.NFData DeviceEvent