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



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

    static #values = new Map([
        ["Unassigned", 0],
        ["UppercaseLetter", 1],
        ["LowercaseLetter", 2],
        ["TitlecaseLetter", 3],
        ["ModifierLetter", 4],
        ["OtherLetter", 5],
        ["NonspacingMark", 6],
        ["EnclosingMark", 7],
        ["SpacingMark", 8],
        ["DecimalNumber", 9],
        ["LetterNumber", 10],
        ["OtherNumber", 11],
        ["SpaceSeparator", 12],
        ["LineSeparator", 13],
        ["ParagraphSeparator", 14],
        ["Control", 15],
        ["Format", 16],
        ["PrivateUse", 17],
        ["Surrogate", 18],
        ["DashPunctuation", 19],
        ["OpenPunctuation", 20],
        ["ClosePunctuation", 21],
        ["ConnectorPunctuation", 22],
        ["OtherPunctuation", 23],
        ["MathSymbol", 24],
        ["CurrencySymbol", 25],
        ["ModifierSymbol", 26],
        ["OtherSymbol", 27],
        ["InitialPunctuation", 28],
        ["FinalPunctuation", 29]
    ]);

    static getAllEntries() {
        return GeneralCategory.#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 GeneralCategory.#objectValues[arguments[1]];
        }

        if (value instanceof GeneralCategory) {
            return value;
        }

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

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

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

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

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

    /** @internal */
    get ffiValue(){
        return this.#value;
    }
    static #objectValues = [
        new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0),
        new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1),
        new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2),
        new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3),
        new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 4),
        new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 5),
        new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 6),
        new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 7),
        new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 8),
        new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 9),
        new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 10),
        new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 11),
        new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 12),
        new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 13),
        new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 14),
        new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 15),
        new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 16),
        new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 17),
        new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 18),
        new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 19),
        new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 20),
        new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 21),
        new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 22),
        new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 23),
        new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 24),
        new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 25),
        new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 26),
        new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 27),
        new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 28),
        new GeneralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 29),
    ];

    /**
     * See the [Rust documentation for `Unassigned`](https://docs.rs/icu/2.2.0/icu/properties/props/enum.GeneralCategory.html#variant.Unassigned) for more information.
     */
    static Unassigned = GeneralCategory.#objectValues[0];
    /**
     * See the [Rust documentation for `UppercaseLetter`](https://docs.rs/icu/2.2.0/icu/properties/props/enum.GeneralCategory.html#variant.UppercaseLetter) for more information.
     */
    static UppercaseLetter = GeneralCategory.#objectValues[1];
    /**
     * See the [Rust documentation for `LowercaseLetter`](https://docs.rs/icu/2.2.0/icu/properties/props/enum.GeneralCategory.html#variant.LowercaseLetter) for more information.
     */
    static LowercaseLetter = GeneralCategory.#objectValues[2];
    /**
     * See the [Rust documentation for `TitlecaseLetter`](https://docs.rs/icu/2.2.0/icu/properties/props/enum.GeneralCategory.html#variant.TitlecaseLetter) for more information.
     */
    static TitlecaseLetter = GeneralCategory.#objectValues[3];
    /**
     * See the [Rust documentation for `ModifierLetter`](https://docs.rs/icu/2.2.0/icu/properties/props/enum.GeneralCategory.html#variant.ModifierLetter) for more information.
     */
    static ModifierLetter = GeneralCategory.#objectValues[4];
    /**
     * See the [Rust documentation for `OtherLetter`](https://docs.rs/icu/2.2.0/icu/properties/props/enum.GeneralCategory.html#variant.OtherLetter) for more information.
     */
    static OtherLetter = GeneralCategory.#objectValues[5];
    /**
     * See the [Rust documentation for `NonspacingMark`](https://docs.rs/icu/2.2.0/icu/properties/props/enum.GeneralCategory.html#variant.NonspacingMark) for more information.
     */
    static NonspacingMark = GeneralCategory.#objectValues[6];
    /**
     * See the [Rust documentation for `EnclosingMark`](https://docs.rs/icu/2.2.0/icu/properties/props/enum.GeneralCategory.html#variant.EnclosingMark) for more information.
     */
    static EnclosingMark = GeneralCategory.#objectValues[7];
    /**
     * See the [Rust documentation for `SpacingMark`](https://docs.rs/icu/2.2.0/icu/properties/props/enum.GeneralCategory.html#variant.SpacingMark) for more information.
     */
    static SpacingMark = GeneralCategory.#objectValues[8];
    /**
     * See the [Rust documentation for `DecimalNumber`](https://docs.rs/icu/2.2.0/icu/properties/props/enum.GeneralCategory.html#variant.DecimalNumber) for more information.
     */
    static DecimalNumber = GeneralCategory.#objectValues[9];
    /**
     * See the [Rust documentation for `LetterNumber`](https://docs.rs/icu/2.2.0/icu/properties/props/enum.GeneralCategory.html#variant.LetterNumber) for more information.
     */
    static LetterNumber = GeneralCategory.#objectValues[10];
    /**
     * See the [Rust documentation for `OtherNumber`](https://docs.rs/icu/2.2.0/icu/properties/props/enum.GeneralCategory.html#variant.OtherNumber) for more information.
     */
    static OtherNumber = GeneralCategory.#objectValues[11];
    /**
     * See the [Rust documentation for `SpaceSeparator`](https://docs.rs/icu/2.2.0/icu/properties/props/enum.GeneralCategory.html#variant.SpaceSeparator) for more information.
     */
    static SpaceSeparator = GeneralCategory.#objectValues[12];
    /**
     * See the [Rust documentation for `LineSeparator`](https://docs.rs/icu/2.2.0/icu/properties/props/enum.GeneralCategory.html#variant.LineSeparator) for more information.
     */
    static LineSeparator = GeneralCategory.#objectValues[13];
    /**
     * See the [Rust documentation for `ParagraphSeparator`](https://docs.rs/icu/2.2.0/icu/properties/props/enum.GeneralCategory.html#variant.ParagraphSeparator) for more information.
     */
    static ParagraphSeparator = GeneralCategory.#objectValues[14];
    /**
     * See the [Rust documentation for `Control`](https://docs.rs/icu/2.2.0/icu/properties/props/enum.GeneralCategory.html#variant.Control) for more information.
     */
    static Control = GeneralCategory.#objectValues[15];
    /**
     * See the [Rust documentation for `Format`](https://docs.rs/icu/2.2.0/icu/properties/props/enum.GeneralCategory.html#variant.Format) for more information.
     */
    static Format = GeneralCategory.#objectValues[16];
    /**
     * See the [Rust documentation for `PrivateUse`](https://docs.rs/icu/2.2.0/icu/properties/props/enum.GeneralCategory.html#variant.PrivateUse) for more information.
     */
    static PrivateUse = GeneralCategory.#objectValues[17];
    /**
     * See the [Rust documentation for `Surrogate`](https://docs.rs/icu/2.2.0/icu/properties/props/enum.GeneralCategory.html#variant.Surrogate) for more information.
     */
    static Surrogate = GeneralCategory.#objectValues[18];
    /**
     * See the [Rust documentation for `DashPunctuation`](https://docs.rs/icu/2.2.0/icu/properties/props/enum.GeneralCategory.html#variant.DashPunctuation) for more information.
     */
    static DashPunctuation = GeneralCategory.#objectValues[19];
    /**
     * See the [Rust documentation for `OpenPunctuation`](https://docs.rs/icu/2.2.0/icu/properties/props/enum.GeneralCategory.html#variant.OpenPunctuation) for more information.
     */
    static OpenPunctuation = GeneralCategory.#objectValues[20];
    /**
     * See the [Rust documentation for `ClosePunctuation`](https://docs.rs/icu/2.2.0/icu/properties/props/enum.GeneralCategory.html#variant.ClosePunctuation) for more information.
     */
    static ClosePunctuation = GeneralCategory.#objectValues[21];
    /**
     * See the [Rust documentation for `ConnectorPunctuation`](https://docs.rs/icu/2.2.0/icu/properties/props/enum.GeneralCategory.html#variant.ConnectorPunctuation) for more information.
     */
    static ConnectorPunctuation = GeneralCategory.#objectValues[22];
    /**
     * See the [Rust documentation for `OtherPunctuation`](https://docs.rs/icu/2.2.0/icu/properties/props/enum.GeneralCategory.html#variant.OtherPunctuation) for more information.
     */
    static OtherPunctuation = GeneralCategory.#objectValues[23];
    /**
     * See the [Rust documentation for `MathSymbol`](https://docs.rs/icu/2.2.0/icu/properties/props/enum.GeneralCategory.html#variant.MathSymbol) for more information.
     */
    static MathSymbol = GeneralCategory.#objectValues[24];
    /**
     * See the [Rust documentation for `CurrencySymbol`](https://docs.rs/icu/2.2.0/icu/properties/props/enum.GeneralCategory.html#variant.CurrencySymbol) for more information.
     */
    static CurrencySymbol = GeneralCategory.#objectValues[25];
    /**
     * See the [Rust documentation for `ModifierSymbol`](https://docs.rs/icu/2.2.0/icu/properties/props/enum.GeneralCategory.html#variant.ModifierSymbol) for more information.
     */
    static ModifierSymbol = GeneralCategory.#objectValues[26];
    /**
     * See the [Rust documentation for `OtherSymbol`](https://docs.rs/icu/2.2.0/icu/properties/props/enum.GeneralCategory.html#variant.OtherSymbol) for more information.
     */
    static OtherSymbol = GeneralCategory.#objectValues[27];
    /**
     * See the [Rust documentation for `InitialPunctuation`](https://docs.rs/icu/2.2.0/icu/properties/props/enum.GeneralCategory.html#variant.InitialPunctuation) for more information.
     */
    static InitialPunctuation = GeneralCategory.#objectValues[28];
    /**
     * See the [Rust documentation for `FinalPunctuation`](https://docs.rs/icu/2.2.0/icu/properties/props/enum.GeneralCategory.html#variant.FinalPunctuation) for more information.
     */
    static FinalPunctuation = GeneralCategory.#objectValues[29];


    /**
     * 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_GeneralCategory_for_char_mv1(ch);

        try {
            return new GeneralCategory(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_GeneralCategory_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_GeneralCategory_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.GeneralCategory.html#method.to_icu4c_value) for more information.
     */
    toIntegerValue() {

        const result = wasm.icu4x_GeneralCategory_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.GeneralCategory.html#method.from_icu4c_value) for more information.
     */
    static fromIntegerValue(other) {
        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);


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

        try {
            if (!diplomatReceive.resultFlag) {
                return null;
            }
            return new GeneralCategory(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_GeneralCategory_try_from_str_mv1(diplomatReceive.buffer, sSlice.ptr);

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

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

            diplomatReceive.free();
        }
    }

    /**
     * Produces a `GeneralCategoryGroup` mask that can represent a group of general categories
     *
     * See the [Rust documentation for `GeneralCategoryGroup`](https://docs.rs/icu/2.2.0/icu/properties/props/struct.GeneralCategoryGroup.html) for more information.
     */
    toGroup() {

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

        try {
            return GeneralCategoryGroup._fromFFI(diplomatRuntime.internalConstructor, result);
        }

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

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