module Drasil.System.LessonPlan (
  LessonPlan,
  mkLessonPlan,
  lsnPlanRefs
) where

import Control.Lens (makeLenses, (^.))
import qualified Data.Map.Strict as M

import Drasil.Database (UID, uid)
import Language.Drasil (Reference)

import Drasil.System.Core (SystemMeta, HasSystemMeta(..))

data LessonPlan = LP {
  LessonPlan -> SystemMeta
_sm :: SystemMeta,
  LessonPlan -> Map UID Reference
_lsnPlanRefs :: M.Map UID Reference
}
makeLenses ''LessonPlan

instance HasSystemMeta LessonPlan where
  systemMeta :: Lens' LessonPlan SystemMeta
systemMeta = (SystemMeta -> f SystemMeta) -> LessonPlan -> f LessonPlan
Lens' LessonPlan SystemMeta
sm

mkLessonPlan :: SystemMeta -> [Reference] -> LessonPlan
mkLessonPlan :: SystemMeta -> [Reference] -> LessonPlan
mkLessonPlan SystemMeta
m [Reference]
rs = SystemMeta -> Map UID Reference -> LessonPlan
LP SystemMeta
m Map UID Reference
refs
  where
    refs :: Map UID Reference
refs = [(UID, Reference)] -> Map UID Reference
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList ([(UID, Reference)] -> Map UID Reference)
-> [(UID, Reference)] -> Map UID Reference
forall a b. (a -> b) -> a -> b
$ (Reference -> (UID, Reference))
-> [Reference] -> [(UID, Reference)]
forall a b. (a -> b) -> [a] -> [b]
map (\Reference
r -> (Reference
r Reference -> Getting UID Reference UID -> UID
forall s a. s -> Getting a s a -> a
^. Getting UID Reference UID
forall c. HasUID c => Getter c UID
Getter Reference UID
uid, Reference
r)) [Reference]
rs