{-# LANGUAGE OverloadedStrings #-} module Servall.Types ( WikiTemplate(..) , Video(..) ) where import Data.Aeson ( (.:) , (.=) , FromJSON(..) , ToJSON(..) , Value(..) , object ) import qualified Data.HashMap.Lazy as HM import Data.Text ( Text ) data WikiTemplate = WikiTemplate { wtName :: Text -- , wtSubName :: Maybe Text , wtFields :: HM.HashMap Text Text } deriving Show data Video = Video { vid :: Text , vtitle :: Text , vdesc :: Text , vduration :: Int } deriving (Eq, Show) instance FromJSON Video where parseJSON (Object o) = Video <$> o .: "id" <*> o .: "title" <*> o .: "description" <*> o .: "duration" instance ToJSON Video where toJSON (Video vid title desc duration) = object [ "id" .= vid , "title" .= title , "description" .= desc , "duration" .= duration ]