{-# OPTIONS_GHC -fno-warn-unused-do-bind #-} -- ihamletFile discards do results

module Jobs.Handler.SendNotification.UserRightsUpdate
  ( dispatchNotificationUserRightsUpdate
  ) where

import Import

import Handler.Utils.Database
import Handler.Utils.Mail
import Jobs.Handler.SendNotification.Utils

import Text.Hamlet
-- import qualified Data.CaseInsensitive as CI

dispatchNotificationUserRightsUpdate :: UserId -> [(SchoolShorthand,Bool,Bool)]-> UserId -> Handler ()
dispatchNotificationUserRightsUpdate  nUser _originalRights jRecipient = userMailT jRecipient $ do
    (User{..}, adminSchools, lecturerSchools)  <-  liftHandlerT . runDB $ do
      user <-getJust nUser
      adminSchools    <- getSchoolsOf nUser UserAdminSchool    UserAdminUser
      lecturerSchools <- getSchoolsOf nUser UserLecturerSchool UserLecturerUser
      return (user,adminSchools,lecturerSchools)
    replaceMailHeader "Auto-Submitted" $ Just "auto-generated"
    setSubjectI $ MsgMailSubjectUserRightsUpdate userDisplayName
    -- MsgRenderer mr <- getMailMsgRenderer
    editNotifications <- mkEditNotifications jRecipient
    addAlternatives $
      providePreferredAlternative ($(ihamletFile "templates/mail/userRightsUpdate.hamlet") :: HtmlUrlI18n UniWorXMessage (Route UniWorX))

