//! zig bindings for uwurandom-rs
//! based on the c bindings for uwurandom-rs, also by me
//! to use this library first generate, this will give you a struct with the "generated" propriety, that is your string
//! when you are done with the string just deuwu
//! ignore _ptr it's for internal use only
const std = @import("std");
const c_uwurandom = @cImport(@cInclude("uwurandom.h"));
const uwurandom = @This();

/// the generated string
generated: []u8,

/// INTERNAL USE ONLY DO NOT TOUCH
_ptr: [*c]u8,

/// this return a struct with generated and _ptr filled out
/// please call deuwu or there will be consequences (a memory leak)
pub fn generate(num: i32) !uwurandom {
    const ptr: [*:0]u8 = c_uwurandom.uwurandom(num);
    std.log.debug("{s}", .{ptr});
    return uwurandom{
        .generated = try std.fmt.allocPrint(std.heap.c_allocator, "{s}", .{ptr}),
        ._ptr = ptr,
    };
}

/// call the c binding to the rust function to deallocate the string
pub fn deuwu(self: uwurandom) void {
    c_uwurandom.deuwu(self._ptr);
}

test "test_it_works" {
    const gen = try generate(10);
    defer gen.deuwu();
    try std.testing.expect(gen.generated.len >= 10);
}
