{-|
Module      : EventLoop.Output.OutputEvent
Description : Library of all the possible 'OutputEvent's in the example implementation.
Copyright   : (c) Sebastiaan la Fleur, 2014
License     : BSD3
Maintainer  : sebastiaan.la.fleur@gmail.com
Stability   : experimental
Portability : All

All different 'OutputEvent's are combined to a single 'OutputEvent' type. 
In this example implementation, the 'EventLoop.Output.Graphical.Graphical' and 'EventLoop.Output.SystemMessage.SystemMessageOut' are modeled.
-}
module EventLoop.Output.OutputEvent where

import EventLoop.Output.Graphical.Graphical
import EventLoop.Output.SystemMessage
import EventLoop.Config
import EventLoop.Json

{-|
 The central 'OutputEvent' type.
-}
data OutputEvent = OutGraphical Graphical
                 | OutSysMessage [SystemMessageOut]
                
{-|
 Instance to express how an 'OutputEvent' can be parsed into a JSON formatted message.
-}                
instance JSONAble OutputEvent where
    toJsonMessage (OutGraphical graph)   = JSONObject [(JSONMember modeS (JSONString graphicalS)), (JSONMember commandS (toJsonMessage graph))]
    toJsonMessage (OutSysMessage ms)  = JSONObject [(JSONMember modeS (JSONString sysmessageanswersS)), (JSONMember answersS (JSONArray (map toJsonMessage ms)))]