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   :: TermId
    }
  | TransactionExamRegister
    { transactionExam   :: ExamId
    , transactionUser   :: UserId
    }
  | TransactionExamDeregister
    { transactionExam   :: ExamId
    , transactionUser   :: UserId
    }
  | TransactionExamResultEdit
    { transactionExam   :: ExamId
    , transactionUser   :: UserId
    }
  | TransactionExamResultDeleted
    { transactionExam   :: ExamId
    , transactionUser   :: UserId
    }
  | TransactionCourseParticipantEdit
    { transactionCourse :: CourseId
    , transactionUser   :: UserId
    }
  | TransactionCourseParticipantDeleted
    { transactionCourse :: CourseId
    , transactionUser   :: UserId
    }
  | TransactionCourseApplicationEdit
    { transactionCourse :: CourseId
    , transactionUser   :: UserId
    , transactionCourseApplication :: CourseApplicationId
    }
  | TransactionCourseApplicationDeleted
    { transactionCourse :: CourseId
    , transactionUser   :: UserId
    , transactionCourseApplication :: CourseApplicationId
    }
  deriving (Eq, Ord, Read, Show, Generic, Typeable)

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

derivePersistFieldJSON ''Transaction
