module Handler.Utils.Course where

import Import
import Handler.Utils.Delete

import qualified Database.Esqueleto as E
  

courseDeleteRoute :: Set CourseId -> DeleteRoute Course
courseDeleteRoute drRecords = DeleteRoute
  { drRecords
  , drGetInfo = \(course `E.InnerJoin` school) -> do
      E.on $ course E.^. CourseSchool E.==. school E.^. SchoolId
      E.orderBy [E.asc $ course E.^. CourseName]
      return (course E.^. CourseName, school E.^. SchoolShorthand, school E.^. SchoolName, course E.^. CourseTerm)
  , drUnjoin = \(course `E.InnerJoin` _) -> course
  , drRenderRecord = \(E.Value cName, _, E.Value sName, E.Value tid') ->
      return [whamlet|
        #{cName} (_{ShortTermIdentifier (unTermKey tid')}, #{sName})
      |]
  , drRecordConfirmString = \(E.Value cName, E.Value ssh', _, E.Value tid') -> 
      return [st|#{termToText (unTermKey tid')}/#{ssh'}/#{cName}|]
  , drCaption = SomeMessage MsgCourseDeleteQuestion
  , drSuccessMessage = SomeMessage MsgCourseDeleted
  , drAbort = error "drAbort undefined"
  , drSuccess = error "drSuccess undefined"
  }
