{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
module Network.PushNotification.IOS.Payload where
import Data.Aeson.TH
import Data.Default
import Data.Text (Text)
import Text.Casing
data ApsPayload = ApsPayload
{ _apsPayload_aps :: Aps
, _apsPayload_custom :: Maybe Text
}
deriving (Show, Read, Eq, Ord)
instance Default ApsPayload where
def = ApsPayload def Nothing
data Aps = Aps
{ _aps_alert :: Maybe ApsAlert
, _aps_badge :: Maybe Int
, _aps_sound :: Maybe Text
, _aps_contentAvailable :: Maybe Int
, _aps_category :: Maybe Text
, _aps_threadId :: Maybe Text
}
deriving (Show, Read, Eq, Ord)
instance Default Aps where
def = Aps
{ _aps_alert = Nothing
, _aps_badge = Nothing
, _aps_sound = Nothing
, _aps_contentAvailable = Nothing
, _aps_category = Nothing
, _aps_threadId = Nothing
}
data ApsAlert = ApsAlert
{ _apsAlert_title :: Text
, _apsAlert_body :: Text
, _apsAlert_launchImage :: Maybe Text
}
deriving (Show, Read, Eq, Ord)
instance Default ApsAlert where
def = ApsAlert
{ _apsAlert_title = ""
, _apsAlert_body = ""
, _apsAlert_launchImage = Nothing
}
$(deriveJSON (defaultOptions { fieldLabelModifier = toKebab . fromHumps . drop 10, omitNothingFields = True }) ''ApsAlert)
$(deriveJSON (defaultOptions { fieldLabelModifier = toKebab . fromHumps . drop 5, omitNothingFields = True }) ''Aps)
$(deriveJSON (defaultOptions { fieldLabelModifier = toKebab . fromHumps . drop 12, omitNothingFields = True }) ''ApsPayload)