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



/**
 * Collection of configurations for the ICU4X fallback algorithm.
 *
 * See the [Rust documentation for `LocaleFallbackConfig`](https://docs.rs/icu/2.2.0/icu/locale/fallback/struct.LocaleFallbackConfig.html) for more information.
 */
export class LocaleFallbackConfig {
    #priority;
    get priority() {
        return this.#priority;
    }
    set priority(value){
        this.#priority = value;
    }
    /** @internal */
    static fromFields(structObj) {
        return new LocaleFallbackConfig(structObj);
    }

    #internalConstructor(structObj) {
        if (typeof structObj !== "object") {
            throw new Error("LocaleFallbackConfig's constructor takes an object of LocaleFallbackConfig's fields.");
        }

        if ("priority" in structObj) {
            this.#priority = new LocaleFallbackPriority(structObj.priority);
        } else {
            throw new Error("Missing required field priority.");
        }

        return this;
    }

    // Return this struct in FFI function friendly format.
    // Returns an array that can be expanded with spread syntax (...)
    _intoFFI(
        dst,
        functionCleanupArena,
        appendArrayMap
    ) {

        this._writeToArrayBuffer(wasm.memory.buffer, dst, functionCleanupArena, appendArrayMap);

        return dst;
    }

    static get _sizeBytes() {
        return 4;
    }

    /// Currently unused, we may want to use later on though:
    static get _sizeAlign() {
        return 4;
    }

    static _fromSuppliedValue(internalConstructor, obj) {
        if (internalConstructor !== diplomatRuntime.internalConstructor) {
            throw new Error("_fromSuppliedValue cannot be called externally.");
        }

        if (obj instanceof LocaleFallbackConfig) {
            return obj;
        }

        return LocaleFallbackConfig.fromFields(obj);
    }

    _writeToArrayBuffer(
        arrayBuffer,
        offset,
        functionCleanupArena,
        appendArrayMap
    ) {
        diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, this.#priority.ffiValue, Int32Array);
    }

    // This struct contains borrowed fields, so this takes in a list of
    // "edges" corresponding to where each lifetime's data may have been borrowed from
    // and passes it down to individual fields containing the borrow.
    // This method does not attempt to handle any dependencies between lifetimes, the caller
    // should handle this when constructing edge arrays.
    static _fromFFI(internalConstructor, ptr) {
        if (internalConstructor !== diplomatRuntime.internalConstructor) {
            throw new Error("LocaleFallbackConfig._fromFFI is not meant to be called externally. Please use the default constructor.");
        }
        let structObj = {};
        const priorityDeref = diplomatRuntime.enumDiscriminant(wasm, ptr);
        structObj.priority = new LocaleFallbackPriority(diplomatRuntime.internalConstructor, priorityDeref);

        return new LocaleFallbackConfig(structObj);
    }


    constructor(structObj) {
        return this.#internalConstructor(...arguments)
    }
}