-- | Aeson options and helpers

{-# OPTIONS_HADDOCK hide #-}

module Blockfrost.Types.Shared.Opts
  ( ToLower
  , aesonOptions
  ) where

import Data.Aeson (Options (..), camelTo2, defaultOptions)
import Data.Char (toLower)
import Deriving.Aeson (StringModifier (..))

data ToLower

instance StringModifier ToLower where
  getStringModifier :: String -> String
getStringModifier String
""       = String
""
  getStringModifier (Char
c : String
xs) = Char -> Char
toLower Char
c forall a. a -> [a] -> [a]
: String
xs

aesonOptions :: Maybe String -> Options
aesonOptions :: Maybe String -> Options
aesonOptions Maybe String
mPrefix = Options
defaultOptions {
   fieldLabelModifier :: String -> String
fieldLabelModifier = Char -> String -> String
camelTo2 Char
'_'  forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String
dropIfPrefixed
 , constructorTagModifier :: String -> String
constructorTagModifier = forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower
 }
 where dropIfPrefixed :: String -> String
dropIfPrefixed = forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. a -> a
id (forall a. Int -> [a] -> [a]
drop forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) a. Foldable t => t a -> Int
length) Maybe String
mPrefix