-- | General switches for the code generation, such as generating profunctor-lenses or not
module Language.PureScript.Bridge.CodeGenSwitches 
    ( Settings (..)
    , ForeignOptions(..)
    , defaultSettings
    , Switch
    , getSettings
    , defaultSwitch
    , noLenses, genLenses
    , useGen, useGenRep
    , genForeign, noForeign, noArgonautCodecs
    , genArgonautCodecs
    ) where


import Data.Monoid (Endo(..))

-- | General settings for code generation
data Settings = Settings
    { Settings -> Bool
generateLenses :: Bool -- ^use purescript-profunctor-lens for generated PS-types?
    , Settings -> Bool
genericsGenRep :: Bool -- ^generate generics using purescript-generics-rep instead of purescript-generics
    , Settings -> Bool
generateArgonautCodecs :: Bool -- ^generate Data.Argonaut.Decode.Class EncodeJson and DecodeJson instances
    , Settings -> Maybe ForeignOptions
generateForeign :: Maybe ForeignOptions -- ^generate Foreign.Generic Encode and Decode instances
    }
    deriving (Settings -> Settings -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Settings -> Settings -> Bool
$c/= :: Settings -> Settings -> Bool
== :: Settings -> Settings -> Bool
$c== :: Settings -> Settings -> Bool
Eq, Int -> Settings -> ShowS
[Settings] -> ShowS
Settings -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Settings] -> ShowS
$cshowList :: [Settings] -> ShowS
show :: Settings -> String
$cshow :: Settings -> String
showsPrec :: Int -> Settings -> ShowS
$cshowsPrec :: Int -> Settings -> ShowS
Show)

data ForeignOptions = ForeignOptions
    { ForeignOptions -> Bool
unwrapSingleConstructors :: Bool
    , ForeignOptions -> Bool
unwrapSingleArguments    :: Bool
    }
    deriving (ForeignOptions -> ForeignOptions -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ForeignOptions -> ForeignOptions -> Bool
$c/= :: ForeignOptions -> ForeignOptions -> Bool
== :: ForeignOptions -> ForeignOptions -> Bool
$c== :: ForeignOptions -> ForeignOptions -> Bool
Eq, Int -> ForeignOptions -> ShowS
[ForeignOptions] -> ShowS
ForeignOptions -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ForeignOptions] -> ShowS
$cshowList :: [ForeignOptions] -> ShowS
show :: ForeignOptions -> String
$cshow :: ForeignOptions -> String
showsPrec :: Int -> ForeignOptions -> ShowS
$cshowsPrec :: Int -> ForeignOptions -> ShowS
Show)

-- | Settings to generate Lenses
defaultSettings :: Settings
defaultSettings :: Settings
defaultSettings = Bool -> Bool -> Bool -> Maybe ForeignOptions -> Settings
Settings Bool
True Bool
True Bool
True forall a. Maybe a
Nothing

-- | you can `mappend` switches to control the code generation
type Switch = Endo Settings


-- | Translate switches into settings
getSettings :: Switch -> Settings
getSettings :: Switch -> Settings
getSettings Switch
switch = forall a. Endo a -> a -> a
appEndo Switch
switch Settings
defaultSettings


-- | Default switches include code generation for lenses
defaultSwitch :: Switch
defaultSwitch :: Switch
defaultSwitch = forall a. Monoid a => a
mempty


-- | Switch off the generatation of profunctor-lenses
noLenses :: Switch
noLenses :: Switch
noLenses = forall a. (a -> a) -> Endo a
Endo forall a b. (a -> b) -> a -> b
$ \Settings
settings -> Settings
settings { generateLenses :: Bool
generateLenses = Bool
False }

-- | Switch off the generatation of argonaut-codecs
noArgonautCodecs :: Switch
noArgonautCodecs :: Switch
noArgonautCodecs = forall a. (a -> a) -> Endo a
Endo forall a b. (a -> b) -> a -> b
$ \Settings
settings ->
  Settings
settings { generateArgonautCodecs :: Bool
generateArgonautCodecs = Bool
False }

-- | Switch on the generatation of profunctor-lenses
genLenses :: Switch
genLenses :: Switch
genLenses = forall a. (a -> a) -> Endo a
Endo forall a b. (a -> b) -> a -> b
$ \Settings
settings -> Settings
settings { generateLenses :: Bool
generateLenses = Bool
True }


-- | Generate generics using purescript-generics-rep
useGenRep :: Switch
useGenRep :: Switch
useGenRep = forall a. (a -> a) -> Endo a
Endo forall a b. (a -> b) -> a -> b
$ \Settings
settings -> Settings
settings { genericsGenRep :: Bool
genericsGenRep = Bool
True }


-- | Generate generics using purescript-generics
useGen :: Switch
useGen :: Switch
useGen = forall a. (a -> a) -> Endo a
Endo forall a b. (a -> b) -> a -> b
$ \Settings
settings -> Settings
settings { genericsGenRep :: Bool
genericsGenRep = Bool
False }

genForeign :: ForeignOptions -> Switch
genForeign :: ForeignOptions -> Switch
genForeign ForeignOptions
opts = forall a. (a -> a) -> Endo a
Endo forall a b. (a -> b) -> a -> b
$ \Settings
settings -> Settings
settings { generateForeign :: Maybe ForeignOptions
generateForeign = forall a. a -> Maybe a
Just ForeignOptions
opts }

genArgonautCodecs :: Switch
genArgonautCodecs :: Switch
genArgonautCodecs = forall a. (a -> a) -> Endo a
Endo forall a b. (a -> b) -> a -> b
$ \Settings
settings ->
  Settings
settings { generateArgonautCodecs :: Bool
generateArgonautCodecs = Bool
True }

noForeign :: Switch
noForeign :: Switch
noForeign = forall a. (a -> a) -> Endo a
Endo forall a b. (a -> b) -> a -> b
$ \Settings
settings -> Settings
settings { generateForeign :: Maybe ForeignOptions
generateForeign = forall a. Maybe a
Nothing }