module Jobs.Handler.SendTestEmail
  ( dispatchJobSendTestEmail
  ) where

import Import 

import Handler.Utils.DateTime

import Text.Shakespeare.Text

import Utils.Lens

dispatchJobSendTestEmail :: Email -> MailContext -> Handler ()
dispatchJobSendTestEmail jEmail jMailContext = mailT jMailContext $ do
  _mailTo .= [Address Nothing jEmail]
  replaceMailHeader "Auto-Submitted" $ Just "auto-generated"
  setSubjectI MsgMailTestSubject
  now <- liftIO getCurrentTime
  nDT <- formatTimeMail SelFormatDateTime now
  nD <- formatTimeMail SelFormatDate now
  nT <- formatTimeMail SelFormatTime now
  addPart $ \(MsgRenderer mr) -> ([text|
    #{mr MsgMailTestContent}

    #{mr MsgMailTestDateTime}
      * #{nDT}
      * #{nD}
      * #{nT}
    |] :: TextUrl (Route UniWorX))
