#include "arc/input/input.h"
#include "input.h"

#include "arc/input/mouse.h"
#include "arc/input/keyboard.h"

#include <SDL.h>
#include <stdlib.h>

void ARC_Input_CreateWithEngineData(ARC_Input **input, ARC_EngineData *data){
    *input = (ARC_Input *)malloc(sizeof(ARC_Input));

    (*input)->event = (SDL_Event *)malloc(sizeof(SDL_Event));

    ARC_Keyboard_CreateWithInput(&((*input)->keyboard), *input);
    ARC_Mouse_CreateWithInput(&((*input)->mouse), *input);
}

void ARC_Input_Destroy(ARC_Input *input){
    ARC_Keyboard_Destroy(input->keyboard);
    ARC_Mouse_Destroy(input->mouse);

    free(input->event);
    free(input);
}

ARC_Bool ARC_Input_Update(ARC_Input *input){
    SDL_PollEvent(input->event);
    if(input->event->type == SDL_QUIT){
        return ARC_False;
    }

    ARC_Keyboard_Update(input->keyboard);
    ARC_Mouse_Update(input->mouse);

    return ARC_True;
}

ARC_Keyboard *ARC_Input_GetKeyboard(ARC_Input *input){
    return input->keyboard;
}

ARC_Mouse *ARC_Input_GetMouse(ARC_Input *input){
    return input->mouse;
}
