module EventLoop.Output.SystemMessage(SystemMessageOut(..)) where

import EventLoop.Json
import EventLoop.Config
import EventLoop.CommonTypes

-- System Messages Out
data SystemMessageOut = CanvasSetup Dimension
                      | Timer Bool
                      | Close
                               
instance JSONAble SystemMessageOut where
    toJsonMessage (CanvasSetup dim) = JSONObject [(JSONMember sysmessageanswerS (JSONString canvassetupS)), (JSONMember dimensionS (dimensionToJsonMessage dim))]
    toJsonMessage (Timer bool)      = JSONObject [(JSONMember sysmessageanswerS (JSONString timerS)), (JSONMember useS (JSONBool bool))]
    toJsonMessage (Close)           = JSONObject [(JSONMember sysmessageanswerS (JSONString closeS))]
    
-- Support Function
dimensionToJsonMessage :: Dimension -> JSONMessage
dimensionToJsonMessage (w, h) = JSONObject [(JSONMember hS (JSONFloat h)), (JSONMember wS (JSONFloat w))]