module Audit.Types
  ( Transaction(..)
  ) where

import ClassyPrelude.Yesod hiding (derivePersistFieldJSON)
import Model.Types.TH.JSON
import Model

import Data.Aeson.TH
import Utils.PathPiece


data Transaction
  = TransactionTermEdit
    { transactionTerm   :: TermIdentifier
    }
  | TransactionExamRegister
    { transactionTerm   :: TermIdentifier
    , transactionSchool :: SchoolShorthand
    , transactionCourse :: CourseShorthand
    , transactionExam   :: ExamName
    , transactionUser   :: UserIdent
    }
  | TransactionExamDeregister
    { transactionTerm   :: TermIdentifier
    , transactionSchool :: SchoolShorthand
    , transactionCourse :: CourseShorthand
    , transactionExam   :: ExamName
    , transactionUser   :: UserIdent
    }
  deriving (Eq, Ord, Read, Show, Generic, Typeable)

deriveJSON defaultOptions
  { constructorTagModifier = camelToPathPiece' 1
  , fieldLabelModifier = camelToPathPiece' 1
  , tagSingleConstructors = True
  , sumEncoding = TaggedObject "transaction" "data"
  } ''Transaction

derivePersistFieldJSON ''Transaction
