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



/**
 * See the [Rust documentation for `GraphemeClusterBreak`](https://docs.rs/icu/2.2.0/icu/properties/props/struct.GraphemeClusterBreak.html) for more information.
 */
export class GraphemeClusterBreak {
    #value = undefined;

    static #values = new Map([
        ["Other", 0],
        ["Control", 1],
        ["Cr", 2],
        ["Extend", 3],
        ["L", 4],
        ["Lf", 5],
        ["Lv", 6],
        ["Lvt", 7],
        ["T", 8],
        ["V", 9],
        ["SpacingMark", 10],
        ["Prepend", 11],
        ["RegionalIndicator", 12],
        ["EBase", 13],
        ["EBaseGaz", 14],
        ["EModifier", 15],
        ["GlueAfterZwj", 16],
        ["Zwj", 17]
    ]);

    static getAllEntries() {
        return GraphemeClusterBreak.#values.entries();
    }

    #internalConstructor(value) {
        if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) {
            // We pass in two internalConstructor arguments to create *new*
            // instances of this type, otherwise the enums are treated as singletons.
            if (arguments[1] === diplomatRuntime.internalConstructor ) {
                this.#value = arguments[2];
                return this;
            }
            return GraphemeClusterBreak.#objectValues[arguments[1]];
        }

        if (value instanceof GraphemeClusterBreak) {
            return value;
        }

        let intVal = GraphemeClusterBreak.#values.get(value);

        // Nullish check, checks for null or undefined
        if (intVal != null) {
            return GraphemeClusterBreak.#objectValues[intVal];
        }

        throw TypeError(value + " is not a GraphemeClusterBreak and does not correspond to any of its enumerator values.");
    }

    /** @internal */
    static fromValue(value) {
        return new GraphemeClusterBreak(value);
    }

    get value(){
        return [...GraphemeClusterBreak.#values.keys()][this.#value];
    }

    /** @internal */
    get ffiValue(){
        return this.#value;
    }
    static #objectValues = [
        new GraphemeClusterBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0),
        new GraphemeClusterBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1),
        new GraphemeClusterBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2),
        new GraphemeClusterBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3),
        new GraphemeClusterBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 4),
        new GraphemeClusterBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 5),
        new GraphemeClusterBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 6),
        new GraphemeClusterBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 7),
        new GraphemeClusterBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 8),
        new GraphemeClusterBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 9),
        new GraphemeClusterBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 10),
        new GraphemeClusterBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 11),
        new GraphemeClusterBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 12),
        new GraphemeClusterBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 13),
        new GraphemeClusterBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 14),
        new GraphemeClusterBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 15),
        new GraphemeClusterBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 16),
        new GraphemeClusterBreak(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 17),
    ];

    /**
     * See the [Rust documentation for `Other`](https://docs.rs/icu/2.2.0/icu/properties/props/struct.GraphemeClusterBreak.html#associatedconstant.Other) for more information.
     */
    static Other = GraphemeClusterBreak.#objectValues[0];
    /**
     * See the [Rust documentation for `Control`](https://docs.rs/icu/2.2.0/icu/properties/props/struct.GraphemeClusterBreak.html#associatedconstant.Control) for more information.
     */
    static Control = GraphemeClusterBreak.#objectValues[1];
    /**
     * See the [Rust documentation for `CR`](https://docs.rs/icu/2.2.0/icu/properties/props/struct.GraphemeClusterBreak.html#associatedconstant.CR) for more information.
     */
    static Cr = GraphemeClusterBreak.#objectValues[2];
    /**
     * See the [Rust documentation for `Extend`](https://docs.rs/icu/2.2.0/icu/properties/props/struct.GraphemeClusterBreak.html#associatedconstant.Extend) for more information.
     */
    static Extend = GraphemeClusterBreak.#objectValues[3];
    /**
     * See the [Rust documentation for `L`](https://docs.rs/icu/2.2.0/icu/properties/props/struct.GraphemeClusterBreak.html#associatedconstant.L) for more information.
     */
    static L = GraphemeClusterBreak.#objectValues[4];
    /**
     * See the [Rust documentation for `LF`](https://docs.rs/icu/2.2.0/icu/properties/props/struct.GraphemeClusterBreak.html#associatedconstant.LF) for more information.
     */
    static Lf = GraphemeClusterBreak.#objectValues[5];
    /**
     * See the [Rust documentation for `LV`](https://docs.rs/icu/2.2.0/icu/properties/props/struct.GraphemeClusterBreak.html#associatedconstant.LV) for more information.
     */
    static Lv = GraphemeClusterBreak.#objectValues[6];
    /**
     * See the [Rust documentation for `LVT`](https://docs.rs/icu/2.2.0/icu/properties/props/struct.GraphemeClusterBreak.html#associatedconstant.LVT) for more information.
     */
    static Lvt = GraphemeClusterBreak.#objectValues[7];
    /**
     * See the [Rust documentation for `T`](https://docs.rs/icu/2.2.0/icu/properties/props/struct.GraphemeClusterBreak.html#associatedconstant.T) for more information.
     */
    static T = GraphemeClusterBreak.#objectValues[8];
    /**
     * See the [Rust documentation for `V`](https://docs.rs/icu/2.2.0/icu/properties/props/struct.GraphemeClusterBreak.html#associatedconstant.V) for more information.
     */
    static V = GraphemeClusterBreak.#objectValues[9];
    /**
     * See the [Rust documentation for `SpacingMark`](https://docs.rs/icu/2.2.0/icu/properties/props/struct.GraphemeClusterBreak.html#associatedconstant.SpacingMark) for more information.
     */
    static SpacingMark = GraphemeClusterBreak.#objectValues[10];
    /**
     * See the [Rust documentation for `Prepend`](https://docs.rs/icu/2.2.0/icu/properties/props/struct.GraphemeClusterBreak.html#associatedconstant.Prepend) for more information.
     */
    static Prepend = GraphemeClusterBreak.#objectValues[11];
    /**
     * See the [Rust documentation for `RegionalIndicator`](https://docs.rs/icu/2.2.0/icu/properties/props/struct.GraphemeClusterBreak.html#associatedconstant.RegionalIndicator) for more information.
     */
    static RegionalIndicator = GraphemeClusterBreak.#objectValues[12];
    /**
     * See the [Rust documentation for `EBase`](https://docs.rs/icu/2.2.0/icu/properties/props/struct.GraphemeClusterBreak.html#associatedconstant.EBase) for more information.
     */
    static EBase = GraphemeClusterBreak.#objectValues[13];
    /**
     * See the [Rust documentation for `EBaseGAZ`](https://docs.rs/icu/2.2.0/icu/properties/props/struct.GraphemeClusterBreak.html#associatedconstant.EBaseGAZ) for more information.
     */
    static EBaseGaz = GraphemeClusterBreak.#objectValues[14];
    /**
     * See the [Rust documentation for `EModifier`](https://docs.rs/icu/2.2.0/icu/properties/props/struct.GraphemeClusterBreak.html#associatedconstant.EModifier) for more information.
     */
    static EModifier = GraphemeClusterBreak.#objectValues[15];
    /**
     * See the [Rust documentation for `GlueAfterZwj`](https://docs.rs/icu/2.2.0/icu/properties/props/struct.GraphemeClusterBreak.html#associatedconstant.GlueAfterZwj) for more information.
     */
    static GlueAfterZwj = GraphemeClusterBreak.#objectValues[16];
    /**
     * See the [Rust documentation for `ZWJ`](https://docs.rs/icu/2.2.0/icu/properties/props/struct.GraphemeClusterBreak.html#associatedconstant.ZWJ) for more information.
     */
    static Zwj = GraphemeClusterBreak.#objectValues[17];


    /**
     * See the [Rust documentation for `for_char`](https://docs.rs/icu/2.2.0/icu/properties/props/trait.EnumeratedProperty.html#tymethod.for_char) for more information.
     */
    static forChar(ch) {

        const result = wasm.icu4x_GraphemeClusterBreak_for_char_mv1(ch);

        try {
            return new GraphemeClusterBreak(diplomatRuntime.internalConstructor, result);
        }

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

    /**
     * Get the "long" name of this property value (returns empty if property value is unknown)
     *
     * See the [Rust documentation for `get`](https://docs.rs/icu/2.2.0/icu/properties/struct.PropertyNamesLongBorrowed.html#method.get) for more information.
     */
    longName() {
        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 9, 4, true);


        const result = wasm.icu4x_GraphemeClusterBreak_long_name_mv1(diplomatReceive.buffer, this.ffiValue);

        try {
            if (!diplomatReceive.resultFlag) {
                return null;
            }
            return new diplomatRuntime.DiplomatSliceStr(wasm, diplomatReceive.buffer,  "string8", []).getValue();
        }

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

    /**
     * Get the "short" name of this property value (returns empty if property value is unknown)
     *
     * See the [Rust documentation for `get`](https://docs.rs/icu/2.2.0/icu/properties/struct.PropertyNamesShortBorrowed.html#method.get) for more information.
     */
    shortName() {
        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 9, 4, true);


        const result = wasm.icu4x_GraphemeClusterBreak_short_name_mv1(diplomatReceive.buffer, this.ffiValue);

        try {
            if (!diplomatReceive.resultFlag) {
                return null;
            }
            return new diplomatRuntime.DiplomatSliceStr(wasm, diplomatReceive.buffer,  "string8", []).getValue();
        }

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

    /**
     * Convert to an integer value usable with ICU4C and `CodePointMapData`
     *
     * See the [Rust documentation for `to_icu4c_value`](https://docs.rs/icu/2.2.0/icu/properties/props/struct.GraphemeClusterBreak.html#method.to_icu4c_value) for more information.
     */
    toIntegerValue() {

        const result = wasm.icu4x_GraphemeClusterBreak_to_integer_value_mv1(this.ffiValue);

        try {
            return result;
        }

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

    /**
     * Convert from an integer value from ICU4C or `CodePointMapData`
     *
     * See the [Rust documentation for `from_icu4c_value`](https://docs.rs/icu/2.2.0/icu/properties/props/struct.GraphemeClusterBreak.html#method.from_icu4c_value) for more information.
     */
    static fromIntegerValue(other) {
        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);


        const result = wasm.icu4x_GraphemeClusterBreak_from_integer_value_mv1(diplomatReceive.buffer, other);

        try {
            if (!diplomatReceive.resultFlag) {
                return null;
            }
            return new GraphemeClusterBreak(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
        }

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

    static tryFromStr(s) {
        let functionCleanupArena = new diplomatRuntime.CleanupArena();

        const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, s)));
        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);


        const result = wasm.icu4x_GraphemeClusterBreak_try_from_str_mv1(diplomatReceive.buffer, sSlice.ptr);

        try {
            if (!diplomatReceive.resultFlag) {
                return null;
            }
            return new GraphemeClusterBreak(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
        }

        finally {
            diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
            functionCleanupArena.free();

            diplomatReceive.free();
        }
    }

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