const std = @import("std");
pub const c = @import("c.zig").c;

pub const InitFlags = packed struct(u32) {
    initAudio: bool = false, // `SDL_INIT_AUDIO` implies `SDL_INIT_EVENTS`
    initVideo: bool = false, // `SDL_INIT_VIDEO` implies `SDL_INIT_EVENTS`, should be initialized on the main thread
    initJoystick: bool = false, // `SDL_INIT_JOYSTICK` implies `SDL_INIT_EVENTS`, should be initialized on the same thread as SDL_INIT_VIDEO on Windows if you don't set SDL_HINT_JOYSTICK_THREAD
    initHaptic: bool = false,
    initGamepad: bool = false, // `SDL_INIT_GAMEPAD` implies `SDL_INIT_JOYSTICK`
    initEvents: bool = false,
    initSensor: bool = false, // `SDL_INIT_SENSOR` implies `SDL_INIT_EVENTS`
    initCamera: bool = false, // `SDL_INIT_CAMERA` implies `SDL_INIT_EVENTS`
    pad0: u23 = 0,
    rsvd: bool = false,
};

pub const AppResult = enum(c_int) {
    appContinue, //Value that requests that the app continue from the main callbacks.
    appSuccess, //Value that requests termination with success from the main callbacks.
    appFailure, //Value that requests termination with error from the main callbacks.
};

pub const AppInit_func = c.SDL_AppInit_func;

pub const AppIterate_func = c.SDL_AppIterate_func;

pub const AppEvent_func = c.SDL_AppEvent_func;

pub const AppQuit_func = c.SDL_AppQuit_func;

pub inline fn init(flags: InitFlags) bool {
    return c.SDL_Init(@bitCast(flags));
}

pub inline fn initSubSystem(flags: InitFlags) bool {
    return c.SDL_InitSubSystem(@bitCast(flags));
}

pub inline fn quitSubSystem(flags: InitFlags) void {
    return c.SDL_QuitSubSystem(@bitCast(flags));
}

pub inline fn wasInit(flags: InitFlags) InitFlags {
    return @bitCast(c.SDL_WasInit(@bitCast(flags)));
}

pub inline fn quit() void {
    return c.SDL_Quit();
}

pub inline fn isMainThread() bool {
    return c.SDL_IsMainThread();
}

pub const MainThreadCallback = c.SDL_MainThreadCallback;

pub inline fn runOnMainThread(callback: MainThreadCallback, userdata: ?*anyopaque, wait_complete: bool) bool {
    return c.SDL_RunOnMainThread(callback, userdata, wait_complete);
}

pub inline fn setAppMetadata(appname: [*c]const u8, appversion: [*c]const u8, appidentifier: [*c]const u8) bool {
    return c.SDL_SetAppMetadata(appname, appversion, appidentifier);
}

pub inline fn setAppMetadataProperty(name: [*c]const u8, value: [*c]const u8) bool {
    return c.SDL_SetAppMetadataProperty(name, value);
}

pub inline fn getAppMetadataProperty(name: [*c]const u8) [*c]const u8 {
    return c.SDL_GetAppMetadataProperty(name);
}
