module Utils.Csv
  ( pathPieceCsv
  ) where

import ClassyPrelude
import Data.Csv hiding (Name)
  
import Language.Haskell.TH (Name)
import Language.Haskell.TH.Lib


pathPieceCsv :: Name -> DecsQ
pathPieceCsv (conT -> t) =
  [d|
    instance ToField $(t) where
      toField = toField . toPathPiece
    instance FromField $(t) where
      parseField = maybe (fail "Could not unmarshal from PathPiece") return . fromPathPiece <=< parseField
  |]
