"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ParamValidatorManager = void 0;
const moment_timezone_1 = __importDefault(require("@golemio/core/dist/shared/moment-timezone"));
class ParamValidatorManager {
}
exports.ParamValidatorManager = ParamValidatorManager;
_a = ParamValidatorManager;
ParamValidatorManager.ASW_ID_FORMAT_REGEXP = /^[0-9]+[_\/]?[0-9]*[_\/]?$/;
ParamValidatorManager.getAswIdsValidator = () => {
    return async (value) => {
        if (!value) {
            return Promise.reject("aswIds must be defined");
        }
        const aswIds = Array.isArray(value) ? value : [value];
        for (const aswId of aswIds) {
            if (typeof aswId !== "string" || !aswId.match(_a.ASW_ID_FORMAT_REGEXP)) {
                return Promise.reject("Invalid aswIds format");
            }
        }
        return true;
    };
};
ParamValidatorManager.getDateValidator = () => {
    return async (date) => {
        if (!date) {
            return Promise.reject("Date must be defined");
        }
        const ms = new Date(date).valueOf();
        if (ms < 0) {
            return Promise.reject("Value is out of range");
        }
        return true;
    };
};
ParamValidatorManager.getTimeFromValidator = () => {
    const defaultTimeQueryParams = {
        hoursBefore: 6,
        hoursAfter: 2 * 24,
    };
    return async (date) => {
        if (!date) {
            return Promise.reject("Date must be defined");
        }
        const timeFrom = (0, moment_timezone_1.default)(date);
        const currentMoment = (0, moment_timezone_1.default)();
        if (timeFrom &&
            !timeFrom.isBetween(currentMoment.clone().subtract(defaultTimeQueryParams.hoursBefore, "hours"), currentMoment.clone().add(defaultTimeQueryParams.hoursAfter, "hours"), undefined, "[]")) {
            return Promise.reject("Parameter timeFrom must be in interval [-6h; +2d]");
        }
    };
};
//# sourceMappingURL=ParamValidatorManager.js.map