module EventLoop.Input.InputEvent where

import EventLoop.Config
import EventLoop.Json
import EventLoop.Input.Keyboard
import EventLoop.Input.Mouse
import EventLoop.Input.SystemMessage

data InputEvent = InMouse Mouse       
                | InKeyboard Keyboard
                | InSysMessage SystemMessageIn
             
instance FromJSON InputEvent where
    fromJsonMessage obj@(JSONObject ms) | keyboardS == type'      = InKeyboard (fromJsonMessage obj)
                                        | mouseS == type'         = InMouse (fromJsonMessage obj)
                                        | systemmessageS == type' = InSysMessage (fromJsonMessage obj) 
                                          where
                                              JSONString type' = retrieveError typeS ms