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

pub const PropertiesID = u32;

pub const Sensor = opaque {
    pub inline fn getSensorProperties(sensor: *Sensor) PropertiesID {
        return c.SDL_GetSensorProperties(sensor);
    }

    pub inline fn getSensorName(sensor: *Sensor) [*c]const u8 {
        return c.SDL_GetSensorName(sensor);
    }

    pub inline fn getSensorType(sensor: *Sensor) SensorType {
        return @intFromEnum(c.SDL_GetSensorType(sensor));
    }

    pub inline fn getSensorNonPortableType(sensor: *Sensor) c_int {
        return c.SDL_GetSensorNonPortableType(sensor);
    }

    pub inline fn getSensorID(sensor: *Sensor) SensorID {
        return c.SDL_GetSensorID(sensor);
    }

    pub inline fn getSensorData(sensor: *Sensor, data: *f32, num_values: c_int) bool {
        return c.SDL_GetSensorData(sensor, @ptrCast(data), num_values);
    }

    pub inline fn closeSensor(sensor: *Sensor) void {
        return c.SDL_CloseSensor(sensor);
    }
};

pub const SensorID = u32;

pub const SensorType = enum(c_int) {
    sensorInvalid, //Returned for an invalid sensor
    sensorUnknown, //Unknown sensor type
    sensorAccel, //Accelerometer
    sensorGyro, //Gyroscope
    sensorAccelL, //Accelerometer for left Joy-Con controller and Wii nunchuk
    sensorGyroL, //Gyroscope for left Joy-Con controller
    sensorAccelR, //Accelerometer for right Joy-Con controller
    sensorGyroR, //Gyroscope for right Joy-Con controller
    sensorCount,
};

pub inline fn getSensors(count: *c_int) ?*SensorID {
    return c.SDL_GetSensors(@ptrCast(count));
}

pub inline fn getSensorNameForID(instance_id: SensorID) [*c]const u8 {
    return c.SDL_GetSensorNameForID(instance_id);
}

pub inline fn getSensorTypeForID(instance_id: SensorID) SensorType {
    return @intFromEnum(c.SDL_GetSensorTypeForID(instance_id));
}

pub inline fn getSensorNonPortableTypeForID(instance_id: SensorID) c_int {
    return c.SDL_GetSensorNonPortableTypeForID(instance_id);
}

pub inline fn openSensor(instance_id: SensorID) ?*Sensor {
    return c.SDL_OpenSensor(instance_id);
}

pub inline fn getSensorFromID(instance_id: SensorID) ?*Sensor {
    return c.SDL_GetSensorFromID(instance_id);
}

pub inline fn updateSensors() void {
    return c.SDL_UpdateSensors();
}
