import '../../globals.js';
// Copyright 2019-2025, University of Colorado Boulder
/**
 * An object that contains a value for each item in an enumeration.
 *
 * @author Jonathan Olson <jonathan.olson@colorado.edu>
 */
import phetCore from './phetCore.js';
import affirm from '../../perennial-alias/js/browser-and-node/affirm.js';
// T = enumeration value type
// U = mapped value type
class EnumerationMap {
    /**
     * @param enumeration
     * @param factory - function( {TEnumeration.*} ) => {*}, maps an enumeration value to any value.
     */
    constructor(enumeration, factory) {
        this._map = new Map();
        this._enumeration = enumeration;
        this._values = enumeration.enumeration.values;
        this._values.forEach(entry => {
            affirm(!this._map.has(entry), 'Enumeration key override problem');
            this._map.set(entry, factory(entry));
        });
    }
    /**
     * Returns the value associated with the given enumeration entry.
     */
    get(entry) {
        affirm(this._values.includes(entry));
        affirm(this._map.has(entry));
        return this._map.get(entry);
    }
    /**
     * Sets the value associated with the given enumeration entry.
     */
    set(entry, value) {
        affirm(this._values.includes(entry));
        this._map.set(entry, value);
    }
    /**
     * Returns a new EnumerationMap with mapped values.
     *
     * @param mapFunction - function( {*}, {TEnumeration.*} ): {*}
     * @returns With the mapped values
     */
    map(mapFunction) {
        return new EnumerationMap(this._enumeration, entry => mapFunction(this.get(entry), entry));
    }
    /**
     * Calls the callback on each item of the enumeration map.
     *
     * @param callback - function(value:*, enumerationValue:*)
     */
    forEach(callback) {
        this._values.forEach(entry => callback(this.get(entry), entry));
    }
    /**
     * Returns the values stored in the map, as an array
     *
     */
    values() {
        return this._values.map(entry => this.get(entry));
    }
}
phetCore.register('EnumerationMap', EnumerationMap);
export default EnumerationMap;
//# sourceMappingURL=EnumerationMap.js.map