-- | Document language for lesson plan notebooks.
module Drasil.DocumentLanguage.Notebook
  (mkNb, LsnDesc, LsnChapter(..), LearnObj(..), Review(..), CaseProb(..), Example(..)
  ) where

import Control.Lens ((^.))

import Drasil.Database (ChunkDB)
import Language.Drasil (Sentence(S), Section, CI, Document(Notebook), BibRef,
  foldlList, SepType(Comma), FoldType(List), fullName, Contents(UlC), ulcc, RawContent(Bib))
import Drasil.System (LessonPlan, HasSystemMeta(..))
import Drasil.Metadata.Documentation (notebook)

import Drasil.DocumentLanguage.Notebook.Core (LsnDesc, LsnChapter(..),
  Intro(..), LearnObj(..), Review(..), CaseProb(..), Example(..), Smmry(..), Apndx(..))
import qualified Drasil.DocLang.Notebook as Lsn (intro, learnObj, caseProb, example,
  appendix, review, reference, summary)
import Drasil.ExtractLsnDesc (extractLsnPlanBib)

-- | Creates a notebook from a lesson description and system information.
mkNb :: LessonPlan -> LsnDesc -> (CI -> CI -> Sentence) -> Document
mkNb :: LessonPlan -> LsnDesc -> (CI -> CI -> Sentence) -> Document
mkNb LessonPlan
plan LsnDesc
dd CI -> CI -> Sentence
comb = Sentence -> Sentence -> [Section] -> Document
Notebook Sentence
nm Sentence
as ([Section] -> Document) -> [Section] -> Document
forall a b. (a -> b) -> a -> b
$ ChunkDB -> LsnDesc -> [Section]
mkSections (LessonPlan
plan LessonPlan -> Getting ChunkDB LessonPlan ChunkDB -> ChunkDB
forall s a. s -> Getting a s a -> a
^. Getting ChunkDB LessonPlan ChunkDB
forall c. HasSystemMeta c => Lens' c ChunkDB
Lens' LessonPlan ChunkDB
systemdb) LsnDesc
dd
  where
    nm :: Sentence
nm = CI
notebook CI -> CI -> Sentence
`comb` (LessonPlan
plan LessonPlan -> Getting CI LessonPlan CI -> CI
forall s a. s -> Getting a s a -> a
^. Getting CI LessonPlan CI
forall c. HasSystemMeta c => Lens' c CI
Lens' LessonPlan CI
sysName)
    as :: Sentence
as = SepType -> FoldType -> [Sentence] -> Sentence
foldlList SepType
Comma FoldType
List ([Sentence] -> Sentence) -> [Sentence] -> Sentence
forall a b. (a -> b) -> a -> b
$ (Person -> Sentence) -> [Person] -> [Sentence]
forall a b. (a -> b) -> [a] -> [b]
map (String -> Sentence
S (String -> Sentence) -> (Person -> String) -> Person -> Sentence
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Person -> String
forall n. HasName n => n -> String
fullName) ([Person] -> [Sentence]) -> [Person] -> [Sentence]
forall a b. (a -> b) -> a -> b
$ LessonPlan
plan LessonPlan -> Getting [Person] LessonPlan [Person] -> [Person]
forall s a. s -> Getting a s a -> a
^. Getting [Person] LessonPlan [Person]
forall c. HasSystemMeta c => Lens' c [Person]
Lens' LessonPlan [Person]
authors

-- | Helper for creating the notebook sections.
mkSections :: ChunkDB -> LsnDesc -> [Section]
mkSections :: ChunkDB -> LsnDesc -> [Section]
mkSections ChunkDB
si LsnDesc
dd = (LsnChapter -> Section) -> LsnDesc -> [Section]
forall a b. (a -> b) -> [a] -> [b]
map LsnChapter -> Section
doit LsnDesc
dd
  where
    doit :: LsnChapter -> Section
    doit :: LsnChapter -> Section
doit (Intro Intro
i)     = Intro -> Section
mkIntro Intro
i
    doit (LearnObj LearnObj
lo) = LearnObj -> Section
mkLearnObj LearnObj
lo
    doit (Review Review
r)    = Review -> Section
mkReview Review
r
    doit (CaseProb CaseProb
cp) = CaseProb -> Section
mkCaseProb CaseProb
cp
    doit (Example Example
e)   = Example -> Section
mkExample Example
e
    doit (Smmry Smmry
s)     = Smmry -> Section
mkSmmry Smmry
s
    doit LsnChapter
BibSec        = BibRef -> Section
mkBib (ChunkDB -> LsnDesc -> BibRef
extractLsnPlanBib ChunkDB
si LsnDesc
dd)
    doit (Apndx Apndx
a)     = Apndx -> Section
mkAppndx Apndx
a

-- | Helper for making the 'Introduction' section.
mkIntro :: Intro -> Section
mkIntro :: Intro -> Section
mkIntro (IntrodProg [Contents]
i) = [Contents] -> [Section] -> Section
Lsn.intro [Contents]
i []

-- | Helper for making the 'Learning Objectives' section.
mkLearnObj :: LearnObj -> Section
mkLearnObj :: LearnObj -> Section
mkLearnObj (LrnObjProg [Contents]
cs) = [Contents] -> [Section] -> Section
Lsn.learnObj [Contents]
cs []

-- | Helper for making the 'Review' section.
mkReview :: Review -> Section
mkReview :: Review -> Section
mkReview (ReviewProg [Contents]
r [Section]
ss) = [Contents] -> [Section] -> Section
Lsn.review [Contents]
r [Section]
ss

-- | Helper for making the 'Case Problem' section.
mkCaseProb :: CaseProb -> Section
mkCaseProb :: CaseProb -> Section
mkCaseProb (CaseProbProg [Contents]
cp [Section]
ss) = [Contents] -> [Section] -> Section
Lsn.caseProb [Contents]
cp [Section]
ss

-- | Helper for making the 'Example' section.
mkExample:: Example -> Section
mkExample :: Example -> Section
mkExample (ExampleProg [Contents]
cs) = [Contents] -> [Section] -> Section
Lsn.example [Contents]
cs []

-- | Helper for making the 'Summary' section.
mkSmmry :: Smmry -> Section
mkSmmry :: Smmry -> Section
mkSmmry (SmmryProg [Contents]
cs) = [Contents] -> [Section] -> Section
Lsn.summary [Contents]
cs []

-- | Helper for making the 'Bibliography' section.
mkBib :: BibRef -> Section
mkBib :: BibRef -> Section
mkBib BibRef
bib = [Contents] -> [Section] -> Section
Lsn.reference [UnlabelledContent -> Contents
UlC (UnlabelledContent -> Contents) -> UnlabelledContent -> Contents
forall a b. (a -> b) -> a -> b
$ RawContent -> UnlabelledContent
ulcc (BibRef -> RawContent
Bib BibRef
bib)] []

-- | Helper for making the 'Appendix' section.
mkAppndx :: Apndx -> Section
mkAppndx :: Apndx -> Section
mkAppndx (ApndxProg [Contents]
cs) = [Contents] -> [Section] -> Section
Lsn.appendix [Contents]
cs []