{-# OPTIONS_GHC -fno-warn-orphans #-}

module Network.Mail.Mime.Instances
  (
  ) where

import ClassyPrelude
import Network.Mail.Mime
import Data.Hashable (Hashable)

import Data.Aeson
import Data.Aeson.TH

import Utils.PathPiece

import Utils (assertM)
  

deriving instance Read Address
deriving instance Ord Address
deriving instance Generic Address

instance Hashable Address

deriveToJSON defaultOptions
  { fieldLabelModifier = intercalate "-" . map toLower . drop 1 . splitCamel
  } ''Address

instance FromJSON Address where
  parseJSON = withObject "Address" $ \obj -> do
    addressName <- assertM (not . null) <$> (obj .:? "name")
    addressEmail <- obj .: "email"
    return Address{..}
