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.GOOL.ClassInterface (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,
        folderNum :: ReadMeInfo -> Int
folderNum = Int
number,
        inputOutput :: ReadMeInfo -> (LangAbbrev, LangAbbrev)
inputOutput = (LangAbbrev, LangAbbrev)
inoutf} =
    [Doc] -> Doc
makeMd [LangAbbrev -> [LangAbbrev] -> Maybe LangAbbrev -> Doc
introInfo LangAbbrev
name [LangAbbrev]
auths forall a b. (a -> b) -> a -> b
$ LangAbbrev -> Maybe LangAbbrev
fieldEmptySTR LangAbbrev
purp,
    Maybe LangAbbrev -> Doc
whatInfo forall a b. (a -> b) -> a -> b
$ LangAbbrev -> Maybe LangAbbrev
fieldEmptySTR LangAbbrev
descr,
    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 = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. NonEmpty a -> [a]
toList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [a] -> Maybe (NonEmpty a)
nonEmpty