aboutsummaryrefslogtreecommitdiff
path: root/spec/src/Thermoprint/Identifiers.hs
blob: e90602c2a27d11b2b8c98ff12c7a7be188d3e63a (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, 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