{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE UndecidableInstances #-}

-- | This module provides types for defining notification events.
module Navi.Event.Types.EventError
  ( EventError (..),
  )
where

import Navi.Prelude

-- | Represents an error when querying an 'Event'.
data EventError = MkEventError
  { -- | The name of the event.
    EventError -> Text
name :: Text,
    -- | Short description of the error.
    EventError -> Text
short :: Text,
    -- | Long description of the error.
    EventError -> Text
long :: Text
  }
  deriving stock (EventError -> EventError -> Bool
(EventError -> EventError -> Bool)
-> (EventError -> EventError -> Bool) -> Eq EventError
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: EventError -> EventError -> Bool
== :: EventError -> EventError -> Bool
$c/= :: EventError -> EventError -> Bool
/= :: EventError -> EventError -> Bool
Eq, Int -> EventError -> ShowS
[EventError] -> ShowS
EventError -> String
(Int -> EventError -> ShowS)
-> (EventError -> String)
-> ([EventError] -> ShowS)
-> Show EventError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> EventError -> ShowS
showsPrec :: Int -> EventError -> ShowS
$cshow :: EventError -> String
show :: EventError -> String
$cshowList :: [EventError] -> ShowS
showList :: [EventError] -> ShowS
Show)

makeFieldLabelsNoPrefix ''EventError

instance Exception EventError where
  displayException :: EventError -> String
displayException EventError
e =
    Text -> String
unpackText
      (Text -> String) -> Text -> String
forall a b. (a -> b) -> a -> b
$ [Text] -> Text
forall a. Monoid a => [a] -> a
mconcat
        [ EventError
e EventError -> Optic' A_Lens NoIx EventError Text -> Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx EventError Text
#name,
          Text
": ",
          EventError
e EventError -> Optic' A_Lens NoIx EventError Text -> Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx EventError Text
#short,
          Text
". ",
          EventError
e EventError -> Optic' A_Lens NoIx EventError Text -> Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx EventError Text
#long
        ]