{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE UndecidableInstances #-}
module Navi.Event.Types
( Event (..),
AnyEvent (..),
RepeatEvent (..),
_NoRepeats,
_AllowRepeats,
ErrorNote (..),
_NoErrNote,
_AllowErrNote,
EventError (..),
EventSuccess (..),
)
where
import Navi.Data.NaviNote (NaviNote)
import Navi.Data.PollInterval (PollInterval)
import Navi.Prelude
import Navi.Services.Types (ServiceType)
data RepeatEvent a
= NoRepeats !(IORef (Maybe a))
| AllowRepeats
makePrisms ''RepeatEvent
instance Show (RepeatEvent a) where
show :: RepeatEvent a -> String
show (NoRepeats IORef (Maybe a)
_) = String
"NoRepeats <ref>"
show RepeatEvent a
AllowRepeats = String
"AllowRepeats"
{-# INLINEABLE show #-}
data ErrorNote
= NoErrNote
| AllowErrNote !(RepeatEvent ())
deriving stock (Int -> ErrorNote -> ShowS
[ErrorNote] -> ShowS
ErrorNote -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ErrorNote] -> ShowS
$cshowList :: [ErrorNote] -> ShowS
show :: ErrorNote -> String
$cshow :: ErrorNote -> String
showsPrec :: Int -> ErrorNote -> ShowS
$cshowsPrec :: Int -> ErrorNote -> ShowS
Show)
makePrisms ''ErrorNote
data EventError = MkEventError
{
EventError -> Text
name :: !Text,
EventError -> Text
short :: !Text,
EventError -> Text
long :: !Text
}
deriving stock (EventError -> EventError -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EventError -> EventError -> Bool
$c/= :: EventError -> EventError -> Bool
== :: EventError -> EventError -> Bool
$c== :: EventError -> EventError -> Bool
Eq, Int -> EventError -> ShowS
[EventError] -> ShowS
EventError -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EventError] -> ShowS
$cshowList :: [EventError] -> ShowS
show :: EventError -> String
$cshow :: EventError -> String
showsPrec :: Int -> EventError -> ShowS
$cshowsPrec :: Int -> EventError -> ShowS
Show)
deriving anyclass (Show EventError
Typeable EventError
SomeException -> Maybe EventError
EventError -> String
EventError -> SomeException
forall e.
Typeable e
-> Show e
-> (e -> SomeException)
-> (SomeException -> Maybe e)
-> (e -> String)
-> Exception e
displayException :: EventError -> String
$cdisplayException :: EventError -> String
fromException :: SomeException -> Maybe EventError
$cfromException :: SomeException -> Maybe EventError
toException :: EventError -> SomeException
$ctoException :: EventError -> SomeException
Exception)
makeFieldLabelsNoPrefix ''EventError
data Event result = MkEvent
{
forall result. Event result -> Text
name :: !Text,
forall result. Event result -> ServiceType result
serviceType :: !(ServiceType result),
forall result. Event result -> PollInterval
pollInterval :: !PollInterval,
forall result. Event result -> result -> Maybe NaviNote
raiseAlert :: result -> Maybe NaviNote,
forall result. Event result -> RepeatEvent result
repeatEvent :: !(RepeatEvent result),
forall result. Event result -> ErrorNote
errorNote :: !ErrorNote
}
makeFieldLabelsNoPrefix ''Event
instance Show (Event result) where
show :: Event result -> String
show Event result
event =
String
"MkEvent {name = "
forall a. Semigroup a => a -> a -> a
<> Text -> String
unpack (Event result
event forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. forall a. IsLabel "name" a => a
#name)
forall a. Semigroup a => a -> a -> a
<> String
", parser = <func>, raiseAlert = <func>, repeatEvent = "
forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> String
show (Event result
event forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. forall a. IsLabel "repeatEvent" a => a
#repeatEvent)
forall a. Semigroup a => a -> a -> a
<> String
", errorNote = "
forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> String
show (Event result
event forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. forall a. IsLabel "errorNote" a => a
#errorNote)
forall a. Semigroup a => a -> a -> a
<> String
"}"
{-# INLINEABLE show #-}
type AnyEvent :: Type
data AnyEvent where
MkAnyEvent :: (Eq result, Show result) => Event result -> AnyEvent
deriving stock instance Show AnyEvent
data EventSuccess result = MkEventSuccess
{ forall result. EventSuccess result -> result
result :: result,
forall result. EventSuccess result -> RepeatEvent result
repeatEvent :: RepeatEvent result,
forall result. EventSuccess result -> result -> Maybe NaviNote
raiseAlert :: result -> Maybe NaviNote
}
makeFieldLabelsNoPrefix ''EventSuccess