aboutsummaryrefslogtreecommitdiff
path: root/spec/src/Thermoprint/Identifiers.hs
blob: 2a0731854468405e8d838c4eb7b7a35e77adc0e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
{-# 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)

newtype PrinterId = PrinterId Integer
                  deriving (Show, Read, Eq, Ord, Num, Real, Integral, Enum, FromHttpApiData, ToHttpApiData, FromJSON, ToJSON, Typeable, Generic, NFData)

newtype JobId = JobId Integer
              deriving (Show, Read, Eq, Ord, Num, Real, Integral, Enum, FromHttpApiData, ToHttpApiData, FromJSON, ToJSON, Typeable, Generic, NFData)

newtype DraftId = DraftId Integer
              deriving (Show, Read, Eq, Ord, Num, Real, Integral, Enum, FromHttpApiData, ToHttpApiData, FromJSON, ToJSON, Typeable, Generic, NFData)

castId :: (Integral a, Enum b) => a -> b
castId = toEnum . fromInteger . toInteger