{-# LANGUAGE DeriveDataTypeable, GeneralizedNewtypeDeriving, RecordWildCards, TemplateHaskell, OverloadedStrings #-}
module Clckwrks.Types
( UUID
, Prefix(..)
, Trust(..)
, NamedLink(..)
) where
import Control.Applicative ((<$>))
import Data.Aeson (ToJSON(..), (.=), object)
import Data.Data (Data, Typeable)
import Data.SafeCopy (SafeCopy(..), base, deriveSafeCopy, safeGet, safePut, contain)
import Data.Text (Text)
import qualified Data.Text.Encoding as T
import Data.UUID.Types (UUID)
import Data.UUID.Orphans ()
import HSP.Google.Analytics (UACCT)
$(deriveSafeCopy 0 'base ''UACCT)
newtype Prefix = Prefix { prefixText :: Text }
deriving (Eq, Ord, Read, Show, Data, Typeable)
instance SafeCopy Prefix where
kind = base
getCopy = contain $ (Prefix . T.decodeUtf8) <$> safeGet
putCopy = contain . safePut . T.encodeUtf8 . prefixText
errorTypeName _ = "Prefix"
data Trust
= Trusted
| Untrusted
deriving (Eq, Ord, Read, Show, Data, Typeable)
$(deriveSafeCopy 0 'base ''Trust)
data NamedLink = NamedLink
{ namedLinkTitle :: Text
, namedLinkURL :: Text
}
deriving (Eq, Read, Show, Data, Typeable)
$(deriveSafeCopy 1 'base ''NamedLink)
instance ToJSON NamedLink where
toJSON (NamedLink{..}) =
object [ "navBarItemName" .= namedLinkTitle
, "navBarItemLink" .= namedLinkURL
]