using PhpefRuntimeCore;

private static int fail(string message) {
    stderr.printf("%s\n", message);
    return 1;
}

int main(string[] args) {
    PhpefRuntimeEmbed.engine_start(args);

    uint8[] hello = {
        0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20,
        0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65
    };

    try {
        PhpefRuntimeCore.register_embedded_resource("/assets/hello.txt", hello);
    } catch (Error e) {
        return fail("register_embedded_resource failed: " + e.message);
    }

    var contents = PhpefRuntimeEmbed.phpfunc_file_get_contents(
        PhpefRuntimeCore.Zval.from_string("phpef-resource:///assets/hello.txt")
    );
    if (contents.to_php_string() != "Hello resource") {
        return fail("file_get_contents(phpef-resource://) returned wrong contents: " + contents.to_php_string());
    }

    PhpefRuntimeEmbed.engine_stop();
    stdout.printf("resource_stream_smoke=ok\n");
    return 0;
}
