{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE UndecidableInstances #-}
module Navi.Event.Toml
( RepeatEventToml (..),
_NoRepeatsToml,
_AllowRepeatsToml,
repeatEventOptDecoder,
repeatEventTomlToVal,
mRepeatEventTomlToVal,
ErrorNoteToml (..),
_NoErrNoteToml,
_ErrNoteAllowRepeatsToml,
_ErrNoteNoRepeatsToml,
errorNoteOptDecoder,
errorNoteTomlToVal,
mErrorNoteTomlToVal,
)
where
import Navi.Event.Types (ErrorNote (..), RepeatEvent (..))
import Navi.Prelude
data RepeatEventToml
= NoRepeatsToml
| AllowRepeatsToml
deriving stock (RepeatEventToml -> RepeatEventToml -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RepeatEventToml -> RepeatEventToml -> Bool
$c/= :: RepeatEventToml -> RepeatEventToml -> Bool
== :: RepeatEventToml -> RepeatEventToml -> Bool
$c== :: RepeatEventToml -> RepeatEventToml -> Bool
Eq, Int -> RepeatEventToml -> ShowS
[RepeatEventToml] -> ShowS
RepeatEventToml -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RepeatEventToml] -> ShowS
$cshowList :: [RepeatEventToml] -> ShowS
show :: RepeatEventToml -> String
$cshow :: RepeatEventToml -> String
showsPrec :: Int -> RepeatEventToml -> ShowS
$cshowsPrec :: Int -> RepeatEventToml -> ShowS
Show)
makePrisms ''RepeatEventToml
instance DecodeTOML RepeatEventToml where
tomlDecoder :: Decoder RepeatEventToml
tomlDecoder =
forall a. DecodeTOML a => Decoder a
tomlDecoder forall (f :: Type -> Type) a b. Functor f => f a -> (a -> b) -> f b
<&> \Bool
b ->
if Bool
b
then RepeatEventToml
AllowRepeatsToml
else RepeatEventToml
NoRepeatsToml
repeatEventOptDecoder :: Decoder (Maybe RepeatEventToml)
repeatEventOptDecoder :: Decoder (Maybe RepeatEventToml)
repeatEventOptDecoder = forall a. Decoder a -> Text -> Decoder (Maybe a)
getFieldOptWith forall a. DecodeTOML a => Decoder a
tomlDecoder Text
"repeat-events"
repeatEventTomlToVal :: MonadIORef m => RepeatEventToml -> m (RepeatEvent a)
repeatEventTomlToVal :: forall (m :: Type -> Type) a.
MonadIORef m =>
RepeatEventToml -> m (RepeatEvent a)
repeatEventTomlToVal RepeatEventToml
AllowRepeatsToml = forall (f :: Type -> Type) a. Applicative f => a -> f a
pure forall a. RepeatEvent a
AllowRepeats
repeatEventTomlToVal RepeatEventToml
NoRepeatsToml = forall a. IORef (Maybe a) -> RepeatEvent a
NoRepeats forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: Type -> Type) a.
(MonadIORef m, HasCallStack) =>
a -> m (IORef a)
newIORef forall a. Maybe a
Nothing
{-# INLINEABLE repeatEventTomlToVal #-}
mRepeatEventTomlToVal :: MonadIORef m => Maybe RepeatEventToml -> m (RepeatEvent a)
mRepeatEventTomlToVal :: forall (m :: Type -> Type) a.
MonadIORef m =>
Maybe RepeatEventToml -> m (RepeatEvent a)
mRepeatEventTomlToVal Maybe RepeatEventToml
Nothing = forall (m :: Type -> Type) a.
MonadIORef m =>
RepeatEventToml -> m (RepeatEvent a)
repeatEventTomlToVal RepeatEventToml
NoRepeatsToml
mRepeatEventTomlToVal (Just RepeatEventToml
t) = forall (m :: Type -> Type) a.
MonadIORef m =>
RepeatEventToml -> m (RepeatEvent a)
repeatEventTomlToVal RepeatEventToml
t
{-# INLINEABLE mRepeatEventTomlToVal #-}
data ErrorNoteToml
= NoErrNoteToml
| ErrNoteAllowRepeatsToml
| ErrNoteNoRepeatsToml
deriving stock (ErrorNoteToml -> ErrorNoteToml -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ErrorNoteToml -> ErrorNoteToml -> Bool
$c/= :: ErrorNoteToml -> ErrorNoteToml -> Bool
== :: ErrorNoteToml -> ErrorNoteToml -> Bool
$c== :: ErrorNoteToml -> ErrorNoteToml -> Bool
Eq, Int -> ErrorNoteToml -> ShowS
[ErrorNoteToml] -> ShowS
ErrorNoteToml -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ErrorNoteToml] -> ShowS
$cshowList :: [ErrorNoteToml] -> ShowS
show :: ErrorNoteToml -> String
$cshow :: ErrorNoteToml -> String
showsPrec :: Int -> ErrorNoteToml -> ShowS
$cshowsPrec :: Int -> ErrorNoteToml -> ShowS
Show)
makePrisms ''ErrorNoteToml
instance DecodeTOML ErrorNoteToml where
tomlDecoder :: Decoder ErrorNoteToml
tomlDecoder =
forall a. DecodeTOML a => Decoder a
tomlDecoder
forall (m :: Type -> Type) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Text
"none" -> forall (f :: Type -> Type) a. Applicative f => a -> f a
pure ErrorNoteToml
NoErrNoteToml
Text
"repeats" -> forall (f :: Type -> Type) a. Applicative f => a -> f a
pure ErrorNoteToml
ErrNoteAllowRepeatsToml
Text
"no-repeats" -> forall (f :: Type -> Type) a. Applicative f => a -> f a
pure ErrorNoteToml
ErrNoteNoRepeatsToml
Text
bad ->
forall (m :: Type -> Type) a. MonadFail m => String -> m a
fail forall a b. (a -> b) -> a -> b
$
Text -> String
unpack forall a b. (a -> b) -> a -> b
$
[Text] -> Text
concat
[ Text
"Unexpected error-events string: ",
Text
bad,
Text
". Expected one of <none | repeats | no-repeats>."
]
errorNoteOptDecoder :: Decoder (Maybe ErrorNoteToml)
errorNoteOptDecoder :: Decoder (Maybe ErrorNoteToml)
errorNoteOptDecoder = forall a. Decoder a -> Text -> Decoder (Maybe a)
getFieldOptWith forall a. DecodeTOML a => Decoder a
tomlDecoder Text
"error-events"
errorNoteTomlToVal :: MonadIORef m => ErrorNoteToml -> m ErrorNote
errorNoteTomlToVal :: forall (m :: Type -> Type).
MonadIORef m =>
ErrorNoteToml -> m ErrorNote
errorNoteTomlToVal ErrorNoteToml
NoErrNoteToml = forall (f :: Type -> Type) a. Applicative f => a -> f a
pure ErrorNote
NoErrNote
errorNoteTomlToVal ErrorNoteToml
ErrNoteAllowRepeatsToml = forall (f :: Type -> Type) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ RepeatEvent () -> ErrorNote
AllowErrNote forall a. RepeatEvent a
AllowRepeats
errorNoteTomlToVal ErrorNoteToml
ErrNoteNoRepeatsToml = RepeatEvent () -> ErrorNote
AllowErrNote forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. IORef (Maybe a) -> RepeatEvent a
NoRepeats forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: Type -> Type) a.
(MonadIORef m, HasCallStack) =>
a -> m (IORef a)
newIORef forall a. Maybe a
Nothing
{-# INLINEABLE errorNoteTomlToVal #-}
mErrorNoteTomlToVal :: MonadIORef m => Maybe ErrorNoteToml -> m ErrorNote
mErrorNoteTomlToVal :: forall (m :: Type -> Type).
MonadIORef m =>
Maybe ErrorNoteToml -> m ErrorNote
mErrorNoteTomlToVal Maybe ErrorNoteToml
Nothing = forall (m :: Type -> Type).
MonadIORef m =>
ErrorNoteToml -> m ErrorNote
errorNoteTomlToVal ErrorNoteToml
ErrNoteNoRepeatsToml
mErrorNoteTomlToVal (Just ErrorNoteToml
t) = forall (m :: Type -> Type).
MonadIORef m =>
ErrorNoteToml -> m ErrorNote
errorNoteTomlToVal ErrorNoteToml
t
{-# INLINEABLE mErrorNoteTomlToVal #-}