import WarpError from "../errors/WarpError.js";
let roaringLoader = null;
let loaderError = null;
try {
    const mod = await import("../../infrastructure/adapters/RoaringLoaderAdapter.js");
    roaringLoader = {
        initRoaring: mod.initRoaring,
        getRoaringBitmap32: mod.getRoaringBitmap32,
        getNativeRoaringAvailable: mod.getNativeRoaringAvailable,
    };
}
catch (err) {
    loaderError = err instanceof Error ? err : new WarpError(String(err), 'E_ROARING_LOAD');
}
function requireLoader() {
    if (roaringLoader !== null) {
        return roaringLoader;
    }
    const cause = loaderError === null ? '' : ` Caused by: ${loaderError.message}`;
    throw new WarpError(`Roaring loader adapter not available.${cause}`, 'E_ROARING_NOT_LOADED');
}
export async function initRoaring(mod) {
    await requireLoader().initRoaring(mod);
}
export function getRoaringBitmap32() {
    return requireLoader().getRoaringBitmap32();
}
export function getNativeRoaringAvailable() {
    if (roaringLoader === null) {
        return false;
    }
    return roaringLoader.getNativeRoaringAvailable();
}
