aboutsummaryrefslogtreecommitdiff
path: root/src/Model/Mail.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Model/Mail.hs')
-rw-r--r--src/Model/Mail.hs77
1 files changed, 60 insertions, 17 deletions
diff --git a/src/Model/Mail.hs b/src/Model/Mail.hs
index e730e32..19ebaeb 100644
--- a/src/Model/Mail.hs
+++ b/src/Model/Mail.hs
@@ -11,22 +11,62 @@ import qualified Data.Text as T
import Model.Date
import Model.Birthdate
-mailSubject :: [Birthdate] -> Text
-mailSubject birthdates =
+data Event =
+ Today
+ | NextWeek
+ deriving (Eq, Show)
+
+mailSubject :: [Birthdate] -> [Birthdate] -> Text
+mailSubject birthdaysToday birthdaysNextWeek =
+ T.concat
+ [ "Hey, "
+ , if length birthdaysToday > 0
+ then mailSubjectSentence Today birthdaysToday
+ else ""
+ , if length birthdaysNextWeek > 0
+ then
+ T.concat
+ [ if length birthdaysToday > 0 then " and " else ""
+ , mailSubjectSentence NextWeek birthdaysNextWeek
+ ]
+ else
+ ""
+ , "!"
+ ]
+
+mailSubjectSentence :: Event -> [Birthdate] -> Text
+mailSubjectSentence event birthdates =
let count = length birthdates
in T.concat
- [ "Hey, "
- , if count > 1 then "there are" else "there is"
+ [ case event of
+ Today -> if count > 1 then "there are" else "there is"
+ NextWeek -> "there will be"
, " "
, T.pack . show $ count
, " birthday"
, if count > 1 then "s" else ""
- , " today!"
+ , " "
+ , if event == Today then "today" else "next week"
]
-mailBody :: Date -> [Birthdate] -> Text
-mailBody currentDate birthdates =
- T.concat $ map (mailLine currentDate) (attachLines birthdates)
+mailBody :: Date -> [Birthdate] -> [Birthdate] -> Text
+mailBody currentDate birthdaysToday birthdaysNextWeek =
+ T.concat
+ [ if length birthdaysToday > 0
+ then mailBodySentence Today currentDate birthdaysToday
+ else ""
+ , if length birthdaysNextWeek > 0
+ then
+ T.concat
+ [ if length birthdaysToday > 0 then " " else ""
+ , mailBodySentence NextWeek currentDate birthdaysNextWeek
+ ]
+ else ""
+ ]
+
+mailBodySentence :: Event -> Date -> [Birthdate] -> Text
+mailBodySentence event currentDate birthdates =
+ T.concat $ map (mailBodyPart event currentDate) (attachLines birthdates)
attachLines :: [Birthdate] -> [(Line, Birthdate)]
attachLines birthdates =
@@ -43,18 +83,21 @@ data Line =
| LastLine
deriving (Eq, Show)
-mailLine :: Date -> (Line, Birthdate) -> Text
-mailLine currDate (line, birthdate) =
+mailBodyPart :: Event -> Date -> (Line, Birthdate) -> Text
+mailBodyPart event currDate (line, birthdate) =
T.concat
[ case line of
- MiddleLine -> ", "
- LastLine -> " and "
- _ -> ""
+ x | x `elem` [SingleLine, FirstLine] ->
+ if event == Today then "Today, " else "Next week, "
+ MiddleLine ->
+ ", "
+ LastLine ->
+ " and "
+ _ ->
+ ""
, fullname birthdate
- , case line of
- x | x `elem` [SingleLine, FirstLine] -> " is now "
- _ -> " is "
+ , if event == Today then " is " else " will be "
, T.pack . show $ age currDate birthdate
, " years old"
- , if line == LastLine then "." else ""
+ , if line == SingleLine || line == LastLine then "." else ""
]