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



/**
 * See the [Rust documentation for `categories`](https://docs.rs/icu/2.1.1/icu/plurals/struct.PluralRules.html#method.categories) for more information.
 */
export class PluralCategories {
    #zero;
    get zero() {
        return this.#zero;
    }
    #one;
    get one() {
        return this.#one;
    }
    #two;
    get two() {
        return this.#two;
    }
    #few;
    get few() {
        return this.#few;
    }
    #many;
    get many() {
        return this.#many;
    }
    #other;
    get other() {
        return this.#other;
    }
    #internalConstructor(structObj, internalConstructor) {
        if (typeof structObj !== "object") {
            throw new Error("PluralCategories's constructor takes an object of PluralCategories's fields.");
        }

        if (internalConstructor !== diplomatRuntime.internalConstructor) {
            throw new Error("PluralCategories is an out struct and can only be created internally.");
        }
        if ("zero" in structObj) {
            this.#zero = structObj.zero;
        } else {
            throw new Error("Missing required field zero.");
        }

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

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

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

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

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

        return this;
    }

    // Return this struct in FFI function friendly format.
    // Returns an array that can be expanded with spread syntax (...)
    _intoFFI(
        functionCleanupArena,
        appendArrayMap
    ) {
        let buffer = diplomatRuntime.DiplomatBuf.struct(wasm, 6, 1);

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

        functionCleanupArena.alloc(buffer);

        return buffer.ptr;
    }

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

        if (obj instanceof PluralCategories) {
            return obj;
        }

        return PluralCategories.fromFields(obj);
    }

    _writeToArrayBuffer(
        arrayBuffer,
        offset,
        functionCleanupArena,
        appendArrayMap
    ) {
        diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, this.#zero, Uint8Array);
        diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 1, this.#one, Uint8Array);
        diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 2, this.#two, Uint8Array);
        diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 3, this.#few, Uint8Array);
        diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 4, this.#many, Uint8Array);
        diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 5, this.#other, Uint8Array);
    }

    // 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("PluralCategories._fromFFI is not meant to be called externally. Please use the default constructor.");
        }
        let structObj = {};
        const zeroDeref = (new Uint8Array(wasm.memory.buffer, ptr, 1))[0] === 1;
        structObj.zero = zeroDeref;
        const oneDeref = (new Uint8Array(wasm.memory.buffer, ptr + 1, 1))[0] === 1;
        structObj.one = oneDeref;
        const twoDeref = (new Uint8Array(wasm.memory.buffer, ptr + 2, 1))[0] === 1;
        structObj.two = twoDeref;
        const fewDeref = (new Uint8Array(wasm.memory.buffer, ptr + 3, 1))[0] === 1;
        structObj.few = fewDeref;
        const manyDeref = (new Uint8Array(wasm.memory.buffer, ptr + 4, 1))[0] === 1;
        structObj.many = manyDeref;
        const otherDeref = (new Uint8Array(wasm.memory.buffer, ptr + 5, 1))[0] === 1;
        structObj.other = otherDeref;

        return new PluralCategories(structObj, internalConstructor);
    }


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