module WeekDaze.Data.Group(
Id,
Membership,
Profile(
getMeetingTimes,
getMaybeLocationId,
getMandatesAttendance
),
groupIdTag,
memberTag,
mandatesAttendanceTag,
meetingTimesTag,
defaultMandatesAttendance,
countNTimeslotsPerWeek,
mkProfile,
) where
import qualified Control.DeepSeq
import qualified Data.Maybe
import qualified Data.Set
import qualified Text.XML.HXT.Arrow.Pickle as HXT
import qualified Text.XML.HXT.DOM.Util
import qualified ToolShed.SelfValidate
import qualified WeekDaze.Size as Size
import qualified WeekDaze.Temporal.Time as Temporal.Time
import WeekDaze.Enhanced.EnhancedBool()
tag :: String
tag = "groupProfile"
groupIdTag :: String
groupIdTag = "groupId"
memberTag :: String
memberTag = "member"
mandatesAttendanceTag :: String
mandatesAttendanceTag = "mandatesAttendance"
meetingTimesTag :: String
meetingTimesTag = "meetingTimes"
defaultMeetingTimes :: Temporal.Time.TimeSet timeslotId
defaultMeetingTimes = Data.Set.empty
defaultMandatesAttendance :: Bool
defaultMandatesAttendance = False
type Id = String
data Profile timeslotId locationId = MkProfile {
getMeetingTimes :: Temporal.Time.TimeSet timeslotId,
getMaybeLocationId :: Maybe locationId,
getMandatesAttendance :: Bool
} deriving (Eq, Read, Show)
instance ToolShed.SelfValidate.SelfValidator (Profile timeslotId locationId) where
getErrors _ = []
instance (
HXT.XmlPickler locationId,
HXT.XmlPickler timeslotId,
Ord timeslotId
) => HXT.XmlPickler (Profile timeslotId locationId) where
xpickle = HXT.xpElem tag . HXT.xpWrap (
Text.XML.HXT.DOM.Util.uncurry3 mkProfile,
\MkProfile {
getMeetingTimes = meetingTimes,
getMaybeLocationId = maybeLocationId,
getMandatesAttendance = mandatesAttendance
} -> (
meetingTimes,
maybeLocationId,
mandatesAttendance
)
) $ HXT.xpTriple (
HXT.xpDefault defaultMeetingTimes . HXT.xpElem meetingTimesTag . HXT.xpWrap (
Data.Set.fromList,
Data.Set.toList
) $ HXT.xpList1 HXT.xpickle
) (
HXT.xpOption HXT.xpickle
) (
defaultMandatesAttendance `HXT.xpDefault` HXT.xpAttr mandatesAttendanceTag HXT.xpickle
)
instance (
Control.DeepSeq.NFData locationId,
Control.DeepSeq.NFData timeslotId
) => Control.DeepSeq.NFData (Profile timeslotId locationId) where
rnf (MkProfile x0 x1 x2) = Control.DeepSeq.rnf (x0, x1, x2)
mkProfile :: Temporal.Time.TimeSet timeslotId -> Maybe locationId -> Bool -> Profile timeslotId locationId
mkProfile meetingTimes locationId mandatesAttendance
| ToolShed.SelfValidate.isValid profile = profile
| otherwise = error $ "WeekDaze.Data.Group.mkProfile:\t" ++ ToolShed.SelfValidate.getFirstError profile ++ "."
where
profile = MkProfile meetingTimes locationId mandatesAttendance
countNTimeslotsPerWeek :: Profile timeslotId locationId -> Size.NTimeslots
countNTimeslotsPerWeek = Data.Set.size . getMeetingTimes
hasLocation :: Profile timeslotId locationId -> Bool
hasLocation = Data.Maybe.isJust . getMaybeLocationId
type Membership = Data.Set.Set Id