{-# LANGUAGE DeriveGeneric, GeneralizedNewtypeDeriving, NoDeriveAnyClass #-} -- | Typesafe identifiers for our various objects module Thermoprint.Identifiers ( PrinterId(..) , JobId(..) , DraftId(..) , castId ) where import Data.Typeable (Typeable) import GHC.Generics (Generic) import Control.DeepSeq (NFData) import Servant.API (ToHttpApiData, FromHttpApiData) import Data.Aeson (FromJSON, ToJSON, FromJSONKey, ToJSONKey) newtype PrinterId = PrinterId Integer deriving (Show, Read, Eq, Ord, Num, Real, Integral, Enum, FromHttpApiData, ToHttpApiData, FromJSON, ToJSON, ToJSONKey, FromJSONKey, Typeable, Generic, NFData) newtype JobId = JobId Integer deriving (Show, Read, Eq, Ord, Num, Real, Integral, Enum, FromHttpApiData, ToHttpApiData, FromJSON, ToJSON, ToJSONKey, FromJSONKey, Typeable, Generic, NFData) newtype DraftId = DraftId Integer deriving (Show, Read, Eq, Ord, Num, Real, Integral, Enum, FromHttpApiData, ToHttpApiData, FromJSON, ToJSON, ToJSONKey, FromJSONKey, Typeable, Generic, NFData) castId :: (Integral a, Enum b) => a -> b castId = toEnum . fromInteger . toInteger