module Network.ABCI.Types.Messages.Common
  ( defaultABCIOptions
  , makeABCILenses
  ) where

import           Control.Lens        ((&), (.~))
import           Control.Lens.TH     (DefName (TopName), lensField, lensRules,
                                      makeLensesWith)
import           Data.Aeson          (Options)
import           Data.Aeson.Casing   (aesonDrop, snakeCase)
import           Language.Haskell.TH
--import           Language.Haskell.TH.Syntax (Name, nameBase)


defaultABCIOptions :: String -> Options
defaultABCIOptions :: String -> Options
defaultABCIOptions prefix :: String
prefix = Int -> (String -> String) -> Options
aesonDrop (String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length String
prefix) String -> String
snakeCase

makeABCILenses :: Name -> DecsQ
makeABCILenses :: Name -> DecsQ
makeABCILenses = LensRules -> Name -> DecsQ
makeLensesWith (LensRules -> Name -> DecsQ) -> LensRules -> Name -> DecsQ
forall a b. (a -> b) -> a -> b
$ LensRules
lensRules
  LensRules -> (LensRules -> LensRules) -> LensRules
forall a b. a -> (a -> b) -> b
& (FieldNamer -> Identity FieldNamer)
-> LensRules -> Identity LensRules
Lens' LensRules FieldNamer
lensField ((FieldNamer -> Identity FieldNamer)
 -> LensRules -> Identity LensRules)
-> FieldNamer -> LensRules -> LensRules
forall s t a b. ASetter s t a b -> b -> s -> t
.~ \_ _ name :: Name
name -> [Name -> DefName
TopName (String -> Name
mkName (String -> Name) -> String -> Name
forall a b. (a -> b) -> a -> b
$ '_' Char -> String -> String
forall a. a -> [a] -> [a]
: Name -> String
nameBase Name
name)]