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

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

import           Data.Aeson.AutoType.CodeGen.Haskell
import           Data.Aeson.AutoType.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 Haskell       = FilePath
defaultHaskellFilename
defaultOutputFilename HaskellStrict = FilePath
defaultHaskellFilename
defaultOutputFilename 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 Haskell       = FilePath -> Text -> HashMap Text Type -> IO ()
writeHaskellModule
writeModule HaskellStrict = FilePath -> Text -> HashMap Text Type -> IO ()
writeHaskellModule
writeModule 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 Haskell       = FilePath -> [FilePath] -> IO ExitCode
runHaskellModule
runModule HaskellStrict = FilePath -> [FilePath] -> IO ExitCode
runHaskellModuleStrict
runModule Elm           = FilePath -> [FilePath] -> IO ExitCode
runElmModule