module Language.Drasil.Code.Imperative.GOOL.LanguageRenderer.LanguagePolymorphic (
  -- * Common Syntax
  doxConfig, readMe,sampleInput, makefile, noRunIfLib, doxDocConfig,
  docIfEnabled
) where

import Language.Drasil (Expr)

import Database.Drasil (ChunkDB)

import GOOL.Drasil (ProgData, GOOLState)

import Language.Drasil.Choices (Comments, ImplementationType(..), Verbosity)
import Language.Drasil.Code.DataDesc (DataDesc)
import Language.Drasil.Code.Imperative.Doxygen.Import (makeDoxConfig)
import Language.Drasil.Code.Imperative.Build.AST (BuildConfig, Runnable,
  DocConfig, doxygenDocConfig)
import Language.Drasil.Code.Imperative.Build.Import (makeBuild)
import Language.Drasil.Code.Imperative.WriteInput (makeInputFile)
import Language.Drasil.Code.Imperative.WriteReadMe (makeReadMe)
import Language.Drasil.Code.Imperative.GOOL.LanguageRenderer (doxConfigName,
  makefileName, sampleInputName, readMeName)

import Language.Drasil.Code.Imperative.GOOL.ClassInterface ( ReadMeInfo(..),
  AuxiliarySym(Auxiliary, AuxHelper, auxHelperDoc, auxFromData))

-- | Defines a Doxygen configuration file.
doxConfig :: (AuxiliarySym r) => r (AuxHelper r) -> String ->
  GOOLState -> Verbosity -> r (Auxiliary r)
doxConfig :: forall (r :: * -> *).
AuxiliarySym r =>
r (AuxHelper r)
-> String -> GOOLState -> Verbosity -> r (Auxiliary r)
doxConfig r (AuxHelper r)
opt String
pName GOOLState
s Verbosity
v = forall (r :: * -> *).
AuxiliarySym r =>
String -> Doc -> r (Auxiliary r)
auxFromData String
doxConfigName (String -> GOOLState -> Doc -> Verbosity -> Doc
makeDoxConfig String
pName GOOLState
s
  (forall (r :: * -> *). AuxiliarySym r => r (AuxHelper r) -> Doc
auxHelperDoc r (AuxHelper r)
opt) Verbosity
v)

-- | Defines a markdown file.
readMe :: (AuxiliarySym r) => ReadMeInfo -> r (Auxiliary r)
readMe :: forall (r :: * -> *).
AuxiliarySym r =>
ReadMeInfo -> r (Auxiliary r)
readMe ReadMeInfo
rmi= forall (r :: * -> *).
AuxiliarySym r =>
String -> Doc -> r (Auxiliary r)
auxFromData String
readMeName (ReadMeInfo -> Doc
makeReadMe ReadMeInfo
rmi)

-- | Defines a sample input file.
sampleInput :: (AuxiliarySym r) => ChunkDB -> DataDesc -> [Expr] ->
  r (Auxiliary r)
sampleInput :: forall (r :: * -> *).
AuxiliarySym r =>
ChunkDB -> DataDesc -> [Expr] -> r (Auxiliary r)
sampleInput ChunkDB
db DataDesc
d [Expr]
sd = forall (r :: * -> *).
AuxiliarySym r =>
String -> Doc -> r (Auxiliary r)
auxFromData String
sampleInputName (ChunkDB -> DataDesc -> [Expr] -> Doc
makeInputFile ChunkDB
db DataDesc
d [Expr]
sd)

-- | Defines a Makefile.
makefile :: (AuxiliarySym r) => Maybe BuildConfig -> Maybe Runnable ->
  Maybe DocConfig -> GOOLState -> ProgData -> r (Auxiliary r)
makefile :: forall (r :: * -> *).
AuxiliarySym r =>
Maybe BuildConfig
-> Maybe Runnable
-> Maybe DocConfig
-> GOOLState
-> ProgData
-> r (Auxiliary r)
makefile Maybe BuildConfig
bc Maybe Runnable
r Maybe DocConfig
d GOOLState
s ProgData
p = forall (r :: * -> *).
AuxiliarySym r =>
String -> Doc -> r (Auxiliary r)
auxFromData String
makefileName (Maybe DocConfig
-> Maybe BuildConfig
-> Maybe Runnable
-> GOOLState
-> ProgData
-> Doc
makeBuild Maybe DocConfig
d Maybe BuildConfig
bc Maybe Runnable
r GOOLState
s ProgData
p)

-- | Changes a 'Runnable' to 'Nothing' if the user chose 'Library' for the 'ImplementationType'.
noRunIfLib :: ImplementationType -> Maybe Runnable -> Maybe Runnable
noRunIfLib :: ImplementationType -> Maybe Runnable -> Maybe Runnable
noRunIfLib ImplementationType
Library Maybe Runnable
_ = forall a. Maybe a
Nothing
noRunIfLib ImplementationType
Program Maybe Runnable
r = Maybe Runnable
r

-- | A DocConfig for Doxygen documentation.
doxDocConfig :: DocConfig
doxDocConfig :: DocConfig
doxDocConfig = String -> DocConfig
doxygenDocConfig String
doxConfigName

-- | Returns Nothing if no comments are enabled.
docIfEnabled :: [Comments] -> DocConfig -> Maybe DocConfig
docIfEnabled :: [Comments] -> DocConfig -> Maybe DocConfig
docIfEnabled [] DocConfig
_ = forall a. Maybe a
Nothing
docIfEnabled [Comments]
_ DocConfig
d = forall a. a -> Maybe a
Just DocConfig
d