modules/shared/regulations.mjs

export { Regulation };

import { CrashTest } from "./crash_tests.mjs";

/**
 * Class representing a regulation
 */
class Regulation {
    /**
     * CNCAP regulation
     * @type {string} */
    static get CNCAP() {
        return "CNCAP";
    }
    /**
     * EuroNCAP regulation
     * @type {string} */
    static get EuroNCAP() {
        return "EuroNCAP";
    }
    /**
     * IIHS regulation
     * @type {string}
     */
    static get IIHS() {
        return "IIHS";
    }
    /**
     * USNCAP regulation
     * @type {string}
     */
    static get USNCAP() {
        return "USNCAP";
    }

    /* Class methods */

    /**
     * Return an array of all the available regulation strings
     * @returns {string[]}
     * @example
     * let regulations = Regulation.GetAll();
     */
    static GetAll() {
        return [Regulation.CNCAP, Regulation.EuroNCAP, Regulation.IIHS, Regulation.USNCAP];
    }

    /**
     * Returns the crash tests we support for a given regulation
     * @param {string} regulation Regulation
     * @returns {string[]}
     * @example
     * let crash_tests = Regulation.CrashTests(Regulation.CNCAP);
     */
    static CrashTests(regulation) {
        if (regulation == Regulation.CNCAP) {
            return [CrashTest.ODB, CrashTest.MPDB];
        } else if (regulation == Regulation.EuroNCAP) {
            return [
                CrashTest.FAR_SIDE,
                CrashTest.FFB,
                CrashTest.MPDB,
                CrashTest.MDB,
                CrashTest.ODB,
                CrashTest.SIDE_POLE
            ];
        } else if (regulation == Regulation.IIHS) {
            return [CrashTest.MDB, CrashTest.ODB, CrashTest.SOB];
        } else if (regulation == Regulation.USNCAP) {
            return [CrashTest.FFB, CrashTest.MDB, CrashTest.SIDE_POLE];
        } else {
            WarningMessage(`Unknown regulation ${regulation} in <Regulation.CrashTests>`);
        }

        return [];
    }
}