{-# LANGUAGE FlexibleContexts #-}

module Data.Lightning.Generic (defaultParse, singleField) where 

import GHC.Generics
import Data.Aeson.Types 

defaultParse :: (Generic a, GFromJSON Zero (Rep a)) => Value -> Parser a
defaultParse :: forall a. (Generic a, GFromJSON Zero (Rep a)) => Value -> Parser a
defaultParse = forall a.
(Generic a, GFromJSON Zero (Rep a)) =>
Options -> Value -> Parser a
genericParseJSON Options
def
    where 
        def :: Options
def = Options
defaultOptions{
              fieldLabelModifier :: String -> String
fieldLabelModifier = forall a. (a -> Bool) -> [a] -> [a]
dropWhile (forall a. Eq a => a -> a -> Bool
==Char
'_') forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
hyphen 
            , omitNothingFields :: Bool
omitNothingFields = Bool
True
            } 
        hyphen :: Char -> Char
hyphen Char
'5' = Char
'-'
        hyphen Char
o = Char
o

singleField :: (Generic a, GFromJSON Zero (Rep a)) => Key -> Value -> Parser a 
singleField :: forall a.
(Generic a, GFromJSON Zero (Rep a)) =>
Key -> Value -> Parser a
singleField Key
k1 (Object Object
v) = Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
k1 forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall a. (Generic a, GFromJSON Zero (Rep a)) => Value -> Parser a
defaultParse 
singleField Key
_ Value
_ = forall a. String -> Parser a
parseFail String
"Object is expected"