module FP.API
    ( module FP.API
    , module FP.API.Types
    ) where
import Data.Text
import FP.API.Types
import Prelude
#ifndef FAY
import Data.Serialize
import GHC.Generics (Generic)
#endif
themeToString :: Theme -> String
themeToString Zenburn = "zenburn"
themeToString Panda   = "panda"
themeToString Monokai = "monokai"
themeName :: Theme -> String
themeName Zenburn = "Zenburn"
themeName Panda = "Panda"
themeName Monokai = "Monokai"
themeDescription :: Theme -> String
themeDescription Zenburn = "A theme based on the popular Zenburn theme"
themeDescription Panda = "The default FP Development Environment theme"
themeDescription Monokai = "A Sublime inspired theme based on Monokai"
enumerateThemes :: [Theme]
enumerateThemes = [Panda,Zenburn,Monokai]
defaultTheme :: Theme
defaultTheme = Panda
defaultFontSize :: Int
defaultFontSize = 14
defaultSearchStyle :: Bool
defaultSearchStyle = False
defaultLicense :: IdeLicense
defaultLicense = ILCommunity
invalidSettingsError :: Text
invalidSettingsError = fromString "Invalid settings file"
serverSessionNotReadyError :: Text
serverSessionNotReadyError = fromString "Server session not yet ready"
projectSettingsPath :: Text
projectSettingsPath = fromString ".project-settings.yml"
validGitBranch :: String -> Bool
validGitBranch = Prelude.all ok where
  ok c = elem c "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_."
data Action
  = DoBuildExecutables
  | DoDeployment
  | DoPrivateProjects
  | DoMakeCommercialProducts
  | DoGitStuff
  | DoExternalEditor
  deriving (Show, Eq
#ifndef FAY
           , Generic
#endif
           )
#ifndef FAY
instance Serialize Action
#endif
describeAction :: Action -> Text
describeAction = fromString . describe where
  describe x =
    case x of
      DoBuildExecutables       -> "build executables"
      DoDeployment             -> "make deployments"
      DoPrivateProjects        -> "have private projects"
      DoGitStuff               -> "perform Git actions"
      DoMakeCommercialProducts -> "use the IDE for commercial work"
      DoExternalEditor         -> "use an external editor"
canDo :: IdeLicense -> Action -> Bool
canDo ILProfessional = const True
canDo ILPersonal     = flip elem [DoBuildExecutables,DoDeployment,DoMakeCommercialProducts,DoGitStuff,DoExternalEditor]
canDo ILCommunity    = flip elem [DoBuildExecutables,DoDeployment,DoMakeCommercialProducts,DoGitStuff,DoExternalEditor]
licenseName :: IdeLicense -> Text
licenseName ILPersonal = fromString "personal"
licenseName ILCommunity = fromString "community"
licenseName ILProfessional = fromString "professional"