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



/**
 * See the [Rust documentation for `DateDifferenceOptions`](https://docs.rs/icu/2.2.0/icu/calendar/options/struct.DateDifferenceOptions.html) for more information.
 */
export class DateDifferenceOptions {
    #largestUnit;
    get largestUnit() {
        return this.#largestUnit;
    }
    set largestUnit(value){
        this.#largestUnit = value;
    }
    /** @internal */
    static fromFields(structObj) {
        return new DateDifferenceOptions(structObj);
    }

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

        if ("largestUnit" in structObj) {
            this.#largestUnit = new DateDurationUnit(structObj.largestUnit);
        } else {
            this.#largestUnit = null;
        }

        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 8;
    }

    /// 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 DateDifferenceOptions) {
            return obj;
        }

        return DateDifferenceOptions.fromFields(obj);
    }

    _writeToArrayBuffer(
        arrayBuffer,
        offset,
        functionCleanupArena,
        appendArrayMap
    ) {
        diplomatRuntime.writeOptionToArrayBuffer(arrayBuffer, offset + 0, this.#largestUnit, 4, 4, (arrayBuffer, offset, jsValue) => diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, jsValue.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("DateDifferenceOptions._fromFFI is not meant to be called externally. Please use the default constructor.");
        }
        let structObj = {};
        const largestUnitDeref = ptr;
        structObj.largestUnit = diplomatRuntime.readOption(wasm, largestUnitDeref, 4, (wasm, offset) => { const deref = diplomatRuntime.enumDiscriminant(wasm, offset); return new DateDurationUnit(diplomatRuntime.internalConstructor, deref) });

        return new DateDifferenceOptions(structObj);
    }


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