"use strict";
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CustomStopIdGroupValidator = void 0;
const MAX_STOP_GROUPS = 50;
const MAX_STOPS_IN_GROUP = 50;
const MAX_STOPS_TOTAL = 50;
class CustomStopIdGroupValidator {
    static isStopIdGroupValid(stopIds) {
        try {
            if (!Array.isArray(stopIds) ||
                stopIds.length === 0 ||
                stopIds.length > MAX_STOPS_IN_GROUP ||
                stopIds.some((stopId) => typeof stopId !== "string" || stopId.length === 0 || stopId.length > 30)) {
                return false;
            }
            return true;
        }
        catch {
            return false;
        }
    }
    static parseStopIdsFromGroup(value) {
        try {
            const parsed = JSON.parse(value);
            const keys = Object.keys(parsed);
            if (keys.length !== 1) {
                return null;
            }
            const priority = Number.parseInt(keys[0]);
            if (Number.isNaN(priority)) {
                return null;
            }
            return parsed[priority];
        }
        catch {
            return null;
        }
    }
}
exports.CustomStopIdGroupValidator = CustomStopIdGroupValidator;
_a = CustomStopIdGroupValidator;
CustomStopIdGroupValidator.validate = (value, _) => {
    if (value instanceof Array) {
        if (value.length === 0 || value.length > MAX_STOP_GROUPS) {
            return false;
        }
        let stopsTotal = 0;
        for (const stopIdGroup of value) {
            const stopIds = _a.parseStopIdsFromGroup(stopIdGroup);
            if (!_a.isStopIdGroupValid(stopIds)) {
                return false;
            }
            stopsTotal += stopIds.length;
            if (stopsTotal > MAX_STOPS_TOTAL) {
                return false;
            }
        }
        return true;
    }
    const stopIds = _a.parseStopIdsFromGroup(value);
    return _a.isStopIdGroupValid(stopIds);
};
//# sourceMappingURL=CustomStopIdGroupValidator.js.map