{-# 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.DAX.Types.Event
-- 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.DAX.Types.Event where

import qualified Amazonka.Core as Core
import Amazonka.DAX.Types.SourceType
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Represents a single occurrence of something interesting within the
-- system. Some examples of events are creating a DAX cluster, adding or
-- removing a node, or rebooting a node.
--
-- /See:/ 'newEvent' smart constructor.
data Event = Event'
  { -- | The source of the event. For example, if the event occurred at the node
    -- level, the source would be the node ID.
    Event -> Maybe Text
sourceName :: Prelude.Maybe Prelude.Text,
    -- | Specifies the origin of this event - a cluster, a parameter group, a
    -- node ID, etc.
    Event -> Maybe SourceType
sourceType :: Prelude.Maybe SourceType,
    -- | The date and time when the event occurred.
    Event -> Maybe POSIX
date :: Prelude.Maybe Core.POSIX,
    -- | A user-defined message associated with the event.
    Event -> Maybe Text
message :: Prelude.Maybe Prelude.Text
  }
  deriving (Event -> Event -> Bool
(Event -> Event -> Bool) -> (Event -> Event -> Bool) -> Eq Event
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Event -> Event -> Bool
$c/= :: Event -> Event -> Bool
== :: Event -> Event -> Bool
$c== :: Event -> Event -> Bool
Prelude.Eq, ReadPrec [Event]
ReadPrec Event
Int -> ReadS Event
ReadS [Event]
(Int -> ReadS Event)
-> ReadS [Event]
-> ReadPrec Event
-> ReadPrec [Event]
-> Read Event
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Event]
$creadListPrec :: ReadPrec [Event]
readPrec :: ReadPrec Event
$creadPrec :: ReadPrec Event
readList :: ReadS [Event]
$creadList :: ReadS [Event]
readsPrec :: Int -> ReadS Event
$creadsPrec :: Int -> ReadS Event
Prelude.Read, Int -> Event -> ShowS
[Event] -> ShowS
Event -> String
(Int -> Event -> ShowS)
-> (Event -> String) -> ([Event] -> ShowS) -> Show Event
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Event] -> ShowS
$cshowList :: [Event] -> ShowS
show :: Event -> String
$cshow :: Event -> String
showsPrec :: Int -> Event -> ShowS
$cshowsPrec :: Int -> Event -> ShowS
Prelude.Show, (forall x. Event -> Rep Event x)
-> (forall x. Rep Event x -> Event) -> Generic Event
forall x. Rep Event x -> Event
forall x. Event -> Rep Event x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Event x -> Event
$cfrom :: forall x. Event -> Rep Event x
Prelude.Generic)

-- |
-- Create a value of 'Event' 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:
--
-- 'sourceName', 'event_sourceName' - The source of the event. For example, if the event occurred at the node
-- level, the source would be the node ID.
--
-- 'sourceType', 'event_sourceType' - Specifies the origin of this event - a cluster, a parameter group, a
-- node ID, etc.
--
-- 'date', 'event_date' - The date and time when the event occurred.
--
-- 'message', 'event_message' - A user-defined message associated with the event.
newEvent ::
  Event
newEvent :: Event
newEvent =
  Event' :: Maybe Text
-> Maybe SourceType -> Maybe POSIX -> Maybe Text -> Event
Event'
    { $sel:sourceName:Event' :: Maybe Text
sourceName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:sourceType:Event' :: Maybe SourceType
sourceType = Maybe SourceType
forall a. Maybe a
Prelude.Nothing,
      $sel:date:Event' :: Maybe POSIX
date = Maybe POSIX
forall a. Maybe a
Prelude.Nothing,
      $sel:message:Event' :: Maybe Text
message = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The source of the event. For example, if the event occurred at the node
-- level, the source would be the node ID.
event_sourceName :: Lens.Lens' Event (Prelude.Maybe Prelude.Text)
event_sourceName :: (Maybe Text -> f (Maybe Text)) -> Event -> f Event
event_sourceName = (Event -> Maybe Text)
-> (Event -> Maybe Text -> Event)
-> Lens Event Event (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Event' {Maybe Text
sourceName :: Maybe Text
$sel:sourceName:Event' :: Event -> Maybe Text
sourceName} -> Maybe Text
sourceName) (\s :: Event
s@Event' {} Maybe Text
a -> Event
s {$sel:sourceName:Event' :: Maybe Text
sourceName = Maybe Text
a} :: Event)

-- | Specifies the origin of this event - a cluster, a parameter group, a
-- node ID, etc.
event_sourceType :: Lens.Lens' Event (Prelude.Maybe SourceType)
event_sourceType :: (Maybe SourceType -> f (Maybe SourceType)) -> Event -> f Event
event_sourceType = (Event -> Maybe SourceType)
-> (Event -> Maybe SourceType -> Event)
-> Lens Event Event (Maybe SourceType) (Maybe SourceType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Event' {Maybe SourceType
sourceType :: Maybe SourceType
$sel:sourceType:Event' :: Event -> Maybe SourceType
sourceType} -> Maybe SourceType
sourceType) (\s :: Event
s@Event' {} Maybe SourceType
a -> Event
s {$sel:sourceType:Event' :: Maybe SourceType
sourceType = Maybe SourceType
a} :: Event)

-- | The date and time when the event occurred.
event_date :: Lens.Lens' Event (Prelude.Maybe Prelude.UTCTime)
event_date :: (Maybe UTCTime -> f (Maybe UTCTime)) -> Event -> f Event
event_date = (Event -> Maybe POSIX)
-> (Event -> Maybe POSIX -> Event)
-> Lens Event Event (Maybe POSIX) (Maybe POSIX)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Event' {Maybe POSIX
date :: Maybe POSIX
$sel:date:Event' :: Event -> Maybe POSIX
date} -> Maybe POSIX
date) (\s :: Event
s@Event' {} Maybe POSIX
a -> Event
s {$sel:date:Event' :: Maybe POSIX
date = Maybe POSIX
a} :: Event) ((Maybe POSIX -> f (Maybe POSIX)) -> Event -> f Event)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> Event
-> f Event
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

-- | A user-defined message associated with the event.
event_message :: Lens.Lens' Event (Prelude.Maybe Prelude.Text)
event_message :: (Maybe Text -> f (Maybe Text)) -> Event -> f Event
event_message = (Event -> Maybe Text)
-> (Event -> Maybe Text -> Event)
-> Lens Event Event (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Event' {Maybe Text
message :: Maybe Text
$sel:message:Event' :: Event -> Maybe Text
message} -> Maybe Text
message) (\s :: Event
s@Event' {} Maybe Text
a -> Event
s {$sel:message:Event' :: Maybe Text
message = Maybe Text
a} :: Event)

instance Core.FromJSON Event where
  parseJSON :: Value -> Parser Event
parseJSON =
    String -> (Object -> Parser Event) -> Value -> Parser Event
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Event"
      ( \Object
x ->
          Maybe Text
-> Maybe SourceType -> Maybe POSIX -> Maybe Text -> Event
Event'
            (Maybe Text
 -> Maybe SourceType -> Maybe POSIX -> Maybe Text -> Event)
-> Parser (Maybe Text)
-> Parser (Maybe SourceType -> Maybe POSIX -> Maybe Text -> Event)
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
"SourceName")
            Parser (Maybe SourceType -> Maybe POSIX -> Maybe Text -> Event)
-> Parser (Maybe SourceType)
-> Parser (Maybe POSIX -> Maybe Text -> Event)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe SourceType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"SourceType")
            Parser (Maybe POSIX -> Maybe Text -> Event)
-> Parser (Maybe POSIX) -> Parser (Maybe Text -> Event)
forall (f :: * -> *) a b. Applicative f => 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
"Date")
            Parser (Maybe Text -> Event) -> Parser (Maybe Text) -> Parser Event
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
"Message")
      )

instance Prelude.Hashable Event

instance Prelude.NFData Event