// generated by diplomat-tool
import wasm from "./diplomat-wasm.mjs";
import * as diplomatRuntime from "./diplomat-runtime.mjs";

const Logger_box_destroy_registry = new FinalizationRegistry((ptr) => {
    wasm.icu4x_Logger_destroy_mv1(ptr);
});

/**
 * An object allowing control over the logging used
 */
export class Logger {
    // Internal ptr reference:
    #ptr = null;

    // Lifetimes are only to keep dependencies alive.
    // Since JS won't garbage collect until there are no incoming edges.
    #selfEdge = [];

    #internalConstructor(symbol, ptr, selfEdge) {
        if (symbol !== diplomatRuntime.internalConstructor) {
            console.error("Logger is an Opaque type. You cannot call its constructor.");
            return;
        }
        this.#ptr = ptr;
        this.#selfEdge = selfEdge;

        // Are we being borrowed? If not, we can register.
        if (this.#selfEdge.length === 0) {
            Logger_box_destroy_registry.register(this, this.#ptr);
        }

        return this;
    }
    /** @internal */
    get ffiValue() {
        return this.#ptr;
    }


    /**
     * Initialize the logger using `simple_logger`
     *
     * Requires the `simple_logger` Cargo feature.
     *
     * Returns `false` if there was already a logger set.
     */
    static initSimpleLogger() {

        const result = wasm.icu4x_Logger_init_simple_logger_mv1();

        try {
            return result;
        }

        finally {
            diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
        }
    }

    constructor(symbol, ptr, selfEdge) {
        return this.#internalConstructor(...arguments)
    }
}