module Language.Drasil.Code.Imperative.WriteReadMe (
  makeReadMe
) where

import Language.Drasil.Choices (ImplementationType(..))
import Language.Drasil.Printers (makeMd, introInfo, verInfo, unsupOS,
    extLibSec, instDoc, endNote, whatInfo)
import Language.Drasil.Code.Imperative.ReadMe.Import (ReadMeInfo(..))

import Prelude hiding ((<>))
import Text.PrettyPrint.HughesPJ (Doc, empty)
import Data.List.NonEmpty (nonEmpty, toList)

-- | Generates a README file.
makeReadMe :: ReadMeInfo -> Doc
makeReadMe :: ReadMeInfo -> Doc
makeReadMe ReadMeInfo {
        langName :: ReadMeInfo -> LangAbbrev
langName = LangAbbrev
progLang,
        langVersion :: ReadMeInfo -> LangAbbrev
langVersion = LangAbbrev
progLangVers,
        invalidOS :: ReadMeInfo -> Maybe LangAbbrev
invalidOS = Maybe LangAbbrev
unsupportedOSs,
        implementType :: ReadMeInfo -> ImplementationType
implementType = ImplementationType
imptype,
        extLibNV :: ReadMeInfo -> [(LangAbbrev, LangAbbrev)]
extLibNV = [(LangAbbrev, LangAbbrev)]
extLibns,
        extLibFP :: ReadMeInfo -> [LangAbbrev]
extLibFP = [LangAbbrev]
extLibfp,
        contributors :: ReadMeInfo -> [LangAbbrev]
contributors = [LangAbbrev]
auths,
        configFP :: ReadMeInfo -> [LangAbbrev]
configFP = [LangAbbrev]
configFPs,
        caseName :: ReadMeInfo -> LangAbbrev
caseName = LangAbbrev
name,
        examplePurpose :: ReadMeInfo -> LangAbbrev
examplePurpose = LangAbbrev
purp,
        exampleDescr :: ReadMeInfo -> LangAbbrev
exampleDescr = LangAbbrev
descr,
        exampleMotivation :: ReadMeInfo -> LangAbbrev
exampleMotivation = LangAbbrev
motiv,
        exampleScope :: ReadMeInfo -> LangAbbrev
exampleScope = LangAbbrev
sc,
        folderNum :: ReadMeInfo -> Int
folderNum = Int
number,
        inputOutput :: ReadMeInfo -> (LangAbbrev, LangAbbrev)
inputOutput = (LangAbbrev, LangAbbrev)
inoutf} =
    [Doc] -> Doc
makeMd [LangAbbrev
-> [LangAbbrev] -> Maybe LangAbbrev -> Maybe LangAbbrev -> Doc
introInfo LangAbbrev
name [LangAbbrev]
auths (LangAbbrev -> Maybe LangAbbrev
fieldEmptySTR LangAbbrev
motiv)
      (LangAbbrev -> Maybe LangAbbrev
fieldEmptySTR LangAbbrev
purp),
    Maybe LangAbbrev -> Maybe LangAbbrev -> Doc
whatInfo (LangAbbrev -> Maybe LangAbbrev
fieldEmptySTR LangAbbrev
descr) (LangAbbrev -> Maybe LangAbbrev
fieldEmptySTR LangAbbrev
sc),
    ImplementationType
-> [LangAbbrev] -> LangAbbrev -> (LangAbbrev, LangAbbrev) -> Doc
makeInstr ImplementationType
imptype [LangAbbrev]
configFPs LangAbbrev
name (LangAbbrev, LangAbbrev)
inoutf,
    LangAbbrev -> LangAbbrev -> Doc
verInfo LangAbbrev
progLang LangAbbrev
progLangVers,
    Maybe LangAbbrev -> Doc
unsupOS Maybe LangAbbrev
unsupportedOSs,
    [(LangAbbrev, LangAbbrev)] -> [LangAbbrev] -> Doc
extLibSec [(LangAbbrev, LangAbbrev)]
extLibns [LangAbbrev]
extLibfp,
    Int -> [LangAbbrev] -> Doc
endNote Int
number [LangAbbrev]
auths] -- add date information to end note for license

-- | Helper for encoding the type of program (either library or controller-based) in a README file.
makeInstr :: ImplementationType -> [FilePath] -> String -> (String, String) -> Doc
makeInstr :: ImplementationType
-> [LangAbbrev] -> LangAbbrev -> (LangAbbrev, LangAbbrev) -> Doc
makeInstr ImplementationType
Library [LangAbbrev]
_ LangAbbrev
_ (LangAbbrev, LangAbbrev)
_ = Doc
empty
makeInstr ImplementationType
Program [LangAbbrev]
cfp LangAbbrev
n (LangAbbrev, LangAbbrev)
inOutf = [LangAbbrev] -> LangAbbrev -> (LangAbbrev, LangAbbrev) -> Doc
instDoc [LangAbbrev]
cfp LangAbbrev
n (LangAbbrev, LangAbbrev)
inOutf

-- |Helper that checks if the field is empty; allowing optional content
-- rendering in a README file
fieldEmptySTR :: String -> Maybe String
fieldEmptySTR :: LangAbbrev -> Maybe LangAbbrev
fieldEmptySTR = (NonEmpty Char -> LangAbbrev)
-> Maybe (NonEmpty Char) -> Maybe LangAbbrev
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap NonEmpty Char -> LangAbbrev
forall a. NonEmpty a -> [a]
toList (Maybe (NonEmpty Char) -> Maybe LangAbbrev)
-> (LangAbbrev -> Maybe (NonEmpty Char))
-> LangAbbrev
-> Maybe LangAbbrev
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LangAbbrev -> Maybe (NonEmpty Char)
forall a. [a] -> Maybe (NonEmpty a)
nonEmpty