{-# LANGUAGE CPP               #-}
{-# LANGUAGE OverloadedStrings #-}
-- | Code generation and test running in different languages. (Switchbox.)
module JsonToType.CodeGen(
    Lang(..)
  , writeModule
  , runModule
  , defaultOutputFilename
  ) where

import           Data.Text(Text)
import qualified Data.HashMap.Strict as Map
import           JsonToType.Type
import           System.Exit

import           JsonToType.CodeGen.Haskell
import           JsonToType.CodeGen.Elm

-- | Available output languages.
data Lang = Haskell
          | HaskellStrict
          | Elm

-- | Default output filname is used, when there is no explicit output file path, or it is "-" (stdout).
-- Default module name is consistent with it.
defaultOutputFilename :: Lang -> FilePath
defaultOutputFilename :: Lang -> FilePath
defaultOutputFilename Lang
Haskell       = FilePath
defaultHaskellFilename
defaultOutputFilename Lang
HaskellStrict = FilePath
defaultHaskellFilename
defaultOutputFilename Lang
Elm           = FilePath
defaultElmFilename

-- | Write a Haskell module to an output file, or stdout if `-` filename is given.
writeModule :: Lang -> FilePath -> Text -> Map.HashMap Text Type -> IO ()
writeModule :: Lang -> FilePath -> Text -> HashMap Text Type -> IO ()
writeModule Lang
Haskell       = FilePath -> Text -> HashMap Text Type -> IO ()
writeHaskellModule
writeModule Lang
HaskellStrict = FilePath -> Text -> HashMap Text Type -> IO ()
writeHaskellModule
writeModule Lang
Elm           = FilePath -> Text -> HashMap Text Type -> IO ()
writeElmModule

-- | Run module in a given language.
runModule :: Lang -> FilePath -> [String] -> IO ExitCode
runModule :: Lang -> FilePath -> [FilePath] -> IO ExitCode
runModule Lang
Haskell       = FilePath -> [FilePath] -> IO ExitCode
runHaskellModule
runModule Lang
HaskellStrict = FilePath -> [FilePath] -> IO ExitCode
runHaskellModuleStrict
runModule Lang
Elm           = FilePath -> [FilePath] -> IO ExitCode
runElmModule