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

import Amazonka.AlexaBusiness.Types.DeviceEventType
import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | The list of device events.
--
-- /See:/ 'newDeviceEvent' smart constructor.
data DeviceEvent = DeviceEvent'
  { -- | The time (in epoch) when the event occurred.
    DeviceEvent -> Maybe POSIX
timestamp :: Prelude.Maybe Data.POSIX,
    -- | The type of device event.
    DeviceEvent -> Maybe DeviceEventType
type' :: Prelude.Maybe DeviceEventType,
    -- | The value of the event.
    DeviceEvent -> Maybe Text
value :: Prelude.Maybe Prelude.Text
  }
  deriving (DeviceEvent -> DeviceEvent -> Bool
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]
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
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. 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:
--
-- 'timestamp', 'deviceEvent_timestamp' - The time (in epoch) when the event occurred.
--
-- 'type'', 'deviceEvent_type' - The type of device event.
--
-- 'value', 'deviceEvent_value' - The value of the event.
newDeviceEvent ::
  DeviceEvent
newDeviceEvent :: DeviceEvent
newDeviceEvent =
  DeviceEvent'
    { $sel:timestamp:DeviceEvent' :: Maybe POSIX
timestamp = forall a. Maybe a
Prelude.Nothing,
      $sel:type':DeviceEvent' :: Maybe DeviceEventType
type' = forall a. Maybe a
Prelude.Nothing,
      $sel:value:DeviceEvent' :: Maybe Text
value = forall a. Maybe a
Prelude.Nothing
    }

-- | The time (in epoch) when the event occurred.
deviceEvent_timestamp :: Lens.Lens' DeviceEvent (Prelude.Maybe Prelude.UTCTime)
deviceEvent_timestamp :: Lens' DeviceEvent (Maybe UTCTime)
deviceEvent_timestamp = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeviceEvent' {Maybe POSIX
timestamp :: Maybe POSIX
$sel:timestamp:DeviceEvent' :: DeviceEvent -> Maybe POSIX
timestamp} -> Maybe POSIX
timestamp) (\s :: DeviceEvent
s@DeviceEvent' {} Maybe POSIX
a -> DeviceEvent
s {$sel:timestamp:DeviceEvent' :: Maybe POSIX
timestamp = Maybe POSIX
a} :: DeviceEvent) 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 type of device event.
deviceEvent_type :: Lens.Lens' DeviceEvent (Prelude.Maybe DeviceEventType)
deviceEvent_type :: Lens' DeviceEvent (Maybe DeviceEventType)
deviceEvent_type = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeviceEvent' {Maybe DeviceEventType
type' :: Maybe DeviceEventType
$sel:type':DeviceEvent' :: DeviceEvent -> Maybe DeviceEventType
type'} -> Maybe DeviceEventType
type') (\s :: DeviceEvent
s@DeviceEvent' {} Maybe DeviceEventType
a -> DeviceEvent
s {$sel:type':DeviceEvent' :: Maybe DeviceEventType
type' = Maybe DeviceEventType
a} :: DeviceEvent)

-- | The value of the event.
deviceEvent_value :: Lens.Lens' DeviceEvent (Prelude.Maybe Prelude.Text)
deviceEvent_value :: Lens' DeviceEvent (Maybe Text)
deviceEvent_value = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeviceEvent' {Maybe Text
value :: Maybe Text
$sel:value:DeviceEvent' :: DeviceEvent -> Maybe Text
value} -> Maybe Text
value) (\s :: DeviceEvent
s@DeviceEvent' {} Maybe Text
a -> DeviceEvent
s {$sel:value:DeviceEvent' :: Maybe Text
value = Maybe Text
a} :: DeviceEvent)

instance Data.FromJSON DeviceEvent where
  parseJSON :: Value -> Parser DeviceEvent
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"DeviceEvent"
      ( \Object
x ->
          Maybe POSIX -> Maybe DeviceEventType -> Maybe Text -> DeviceEvent
DeviceEvent'
            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
"Timestamp")
            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
"Type")
            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
"Value")
      )

instance Prelude.Hashable DeviceEvent where
  hashWithSalt :: Int -> DeviceEvent -> Int
hashWithSalt Int
_salt DeviceEvent' {Maybe Text
Maybe POSIX
Maybe DeviceEventType
value :: Maybe Text
type' :: Maybe DeviceEventType
timestamp :: Maybe POSIX
$sel:value:DeviceEvent' :: DeviceEvent -> Maybe Text
$sel:type':DeviceEvent' :: DeviceEvent -> Maybe DeviceEventType
$sel:timestamp:DeviceEvent' :: DeviceEvent -> Maybe POSIX
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe POSIX
timestamp
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe DeviceEventType
type'
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
value

instance Prelude.NFData DeviceEvent where
  rnf :: DeviceEvent -> ()
rnf DeviceEvent' {Maybe Text
Maybe POSIX
Maybe DeviceEventType
value :: Maybe Text
type' :: Maybe DeviceEventType
timestamp :: Maybe POSIX
$sel:value:DeviceEvent' :: DeviceEvent -> Maybe Text
$sel:type':DeviceEvent' :: DeviceEvent -> Maybe DeviceEventType
$sel:timestamp:DeviceEvent' :: DeviceEvent -> Maybe POSIX
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe POSIX
timestamp
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe DeviceEventType
type'
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
value