-- | A module for documenting Scala source files using @scaladoc@.
module Lastik.Scala.Scaladoc(
                             Scaladoc,
                             debug,
                             nowarn,
                             verbose,
                             deprecation,
                             unchecked,
                             classpath,
                             sourcepath,
                             bootclasspath,
                             extdirs,
                             directory,
                             encoding,
                             target,
                             print,
                             optimise,
                             explaintypes,
                             uniqid,
                             version,
                             help,
                             (#),
                             access,
                             bottom,
                             charset,
                             doctitle,
                             footer,
                             header,
                             linksource,
                             nocomment,
                             stylesheetfile,
                             top,
                             windowtitle,
                             etc,
                             scaladoc,
                             scaladoc'
                            )where

import Prelude hiding (print)
import Lastik.Util
import Lastik.Scala.Target
import Lastik.Scala.Debug
import Lastik.Scala.Access
import Lastik.Scala.Scalac (kscalac, scalac')
import Lastik.Compile
import Lastik.Output
import Lastik.Extension

-- | Javadoc is the compiler for Scala API documentation.
data Scaladoc = Scaladoc {
  debug :: Maybe Debug,           -- ^ @-g@
  nowarn :: Bool,                 -- ^ @-nowarn@
  verbose :: Bool,                -- ^ @-verbose@
  deprecation :: Bool,            -- ^ @-deprecation@
  unchecked :: Bool,              -- ^ @-unchecked@
  classpath :: [FilePath],        -- ^ @-classpath@
  sourcepath :: [FilePath],       -- ^ @-sourcepath@
  bootclasspath :: [FilePath],    -- ^ @-bootclasspath@
  extdirs :: [FilePath],          -- ^ @-extdirs@
  directory :: Maybe FilePath,    -- ^ @-d@
  encoding :: Maybe String,       -- ^ @-encoding@
  target :: Maybe Target,         -- ^ @-target@
  print :: Bool,                  -- ^ @-print@
  optimise :: Bool,               -- ^ @-optimise@
  explaintypes :: Bool,           -- ^ @-explaintypes@
  uniqid :: Bool,                 -- ^ @-uniqid@
  version :: Bool,                -- ^ @-version@
  help :: Bool,                   -- ^ @-help@
  (#) :: Maybe FilePath,          -- ^ @\@@
  access :: Maybe Access,         -- ^ @-access@
  bottom :: Maybe String,         -- ^ @-bottom@
  charset :: Maybe String,        -- ^ @-charset@
  doctitle :: Maybe String,       -- ^ @-doctitle@
  footer :: Maybe String,         -- ^ @-footer@
  header :: Maybe String,         -- ^ @-header@
  linksource :: Bool,             -- ^ @-linksource@
  nocomment :: Bool,              -- ^ @-nocomment@
  stylesheetfile :: Maybe String, -- ^ @-stylesheetfile@
  top :: Maybe String,            -- ^ @-top@
  windowtitle :: Maybe String,    -- ^ @-windowtitle@
  etc :: Maybe String
}

-- | A @Scaladoc@ with nothing set.
scaladoc :: Scaladoc
scaladoc = Scaladoc Nothing False False False False [] [] [] [] Nothing Nothing Nothing False False False False False False Nothing Nothing Nothing Nothing Nothing Nothing Nothing False False Nothing Nothing Nothing Nothing

-- | Construct a @Scaladoc@.
scaladoc' :: Maybe Debug
             -> Bool
             -> Bool
              -> Bool
             -> Bool
             -> [FilePath]
             -> [FilePath]
             -> [FilePath]
             -> [FilePath]
             -> Maybe FilePath
             -> Maybe String
             -> Maybe Target
             -> Bool
             -> Bool
             -> Bool
             -> Bool
             -> Bool
             -> Bool
             -> Maybe FilePath
             -> Maybe Access
             -> Maybe String
             -> Maybe String
             -> Maybe String
             -> Maybe String
             -> Maybe String
             -> Bool
             -> Bool
             -> Maybe String
             -> Maybe String
             -> Maybe String
             -> Maybe String
             -> Scaladoc
scaladoc' = Scaladoc

instance Show Scaladoc where
  show (Scaladoc debug
                 nowarn
                 verbose
                 deprecation
                 unchecked
                 classpath
                 sourcepath
                 bootclasspath
                 extdirs
                 directory
                 encoding
                 target
                 print
                 optimise
                 explaintypes
                 uniqid
                 version
                 help
                 script
                 access
                 bottom
                 charset
                 doctitle
                 footer
                 header
                 linksource
                 nocomment
                 stylesheetfile
                 top
                 windowtitle
                 etc) = (kscalac (scalac' debug nowarn verbose deprecation unchecked classpath sourcepath bootclasspath extdirs directory encoding target print optimise explaintypes uniqid version help script etc) ++ ["access" -~> show $ access,
                                      "bottom" ~~~> bottom,
                                      "charset" ~~~> charset,
                                      "doctitle" ~~~> doctitle,
                                      "footer" ~~~> footer,
                                      "header" ~~~> header,
                                      "linksource" ~~ linksource,
                                      "nocomment" ~~ nocomment,
                                      "stylesheetfile" ~~~> stylesheetfile,
                                      "top" ~~~> top,
                                      "windowtitle" ~~~> windowtitle]) ^^^ " "

instance Compile Scaladoc where
  compile s ps = "scaladoc " ++ show s ++ ' ' : space ps

instance Output Scaladoc where
  output = Lastik.Scala.Scaladoc.directory

instance Extension Scaladoc where
  ext _ = "scala"

instance OutputReference Scaladoc where
  reference p s = s { Lastik.Scala.Scaladoc.classpath = p }
  reference' = Lastik.Scala.Scaladoc.classpath