module App.PermissionLevel where import Prelude import Data.Codec.Argonaut as CA import Data.Codec.Argonaut.Variant as CAV import Data.Variant as V import Data.Profunctor (dimap) import Data.Either (Either(..)) import Type.Proxy (Proxy(..)) data PermissionLevel = None | Read | Edit | Admin codec ∷ CA.JsonCodec PermissionLevel codec = dimap toVariant fromVariant $ CAV.variantMatch { permission: Right CA.string } where toVariant = case _ of None → V.inj (Proxy ∷ _ "permission") "none" Read → V.inj (Proxy ∷ _ "permission") "read" Edit → V.inj (Proxy ∷ _ "permission") "edit" Admin → V.inj (Proxy ∷ _ "permission") "admin" fromVariant = V.match { permission: \s -> case s of "none" -> None "read" -> Read "edit" -> Edit "admin" -> Admin _ -> None }