module Model.Migration.Types where 

import ClassyPrelude.Yesod
import Data.Aeson.TH (deriveJSON, defaultOptions)
import Database.Persist.Sql

import qualified Model as Current
import qualified Model.Types.JSON as Current

data SheetType
  = Bonus  { maxPoints :: Current.Points } -- Erhöht nicht das Maximum, wird gutgeschrieben
  | Normal { maxPoints :: Current.Points } -- Erhöht das Maximum, wird gutgeschrieben
  | Pass   { maxPoints, passingPoints :: Current.Points }
  | NotGraded
  deriving (Show, Read, Eq)

sheetType :: SheetType -> Current.SheetType
sheetType Bonus {..}  = Current.Bonus  Current.Points {..}
sheetType Normal {..} = Current.Normal Current.Points {..}
sheetType Pass {..}   = Current.Normal Current.PassPoints {..}
sheetType NotGraded   = Current.NotGraded

{- TODO:
  * RenderMessage instance for newtype(SheetType) if needed
-}


deriveJSON defaultOptions ''SheetType
Current.derivePersistFieldJSON ''SheetType
