halogen-websocket-ipc-playzone/src/App/PermissionLevel.purs

31 lines
675 B
Plaintext
Raw Normal View History

module App.PermissionLevel where
import Data.Codec.Argonaut as CA
2023-05-31 00:22:38 +02:00
import Data.Maybe (Maybe(..))
data PermissionLevel
= None
| Read
| Edit
| Admin
2023-05-31 00:22:38 +02:00
-- | Codec for just encoding a single value of type `PermissionLevel`
codec :: CA.JsonCodec PermissionLevel
codec =
2023-05-31 00:22:38 +02:00
CA.prismaticCodec "PermissionLevel" from to CA.string
where
2023-05-31 00:22:38 +02:00
from :: String -> Maybe PermissionLevel
from = case _ of
"none" -> Just None
"read" -> Just Read
"edit" -> Just Edit
"admin" -> Just Admin
_ -> Nothing
2023-05-31 00:22:38 +02:00
to :: PermissionLevel -> String
to = case _ of
None -> "none"
Read -> "read"
Edit -> "edit"
Admin -> "admin"