"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RopidRouterUtils = void 0;
const Logger_1 = require("@golemio/core/dist/output-gateway/Logger");
const config_1 = require("@golemio/core/dist/output-gateway/config");
const class_transformer_1 = require("@golemio/core/dist/shared/class-transformer");
const moment_timezone_1 = __importDefault(require("@golemio/core/dist/shared/moment-timezone"));
class RopidRouterUtils {
}
exports.RopidRouterUtils = RopidRouterUtils;
RopidRouterUtils.TIMEZONE = "Europe/Prague";
/**
 * Convert plain object to DTO class instance
 */
RopidRouterUtils.mapObjectToDTOInstance = (dto, data) => {
    return (0, class_transformer_1.plainToInstance)(dto, data, { exposeDefaultValues: true });
};
/**
 * Format to ISO 8601 (without milliseconds)
 */
RopidRouterUtils.formatTimestamp = (dateObject, preferredTimezone = RopidRouterUtils.TIMEZONE) => {
    if (!dateObject)
        return null;
    try {
        const datetime = (0, moment_timezone_1.default)(dateObject).tz(preferredTimezone).format();
        if (datetime === "Invalid date") {
            Logger_1.log.error("RopidRouterUtils.formatTimestamp Date conversion error");
            return null;
        }
        return datetime;
    }
    catch (err) {
        Logger_1.log.error("RopidRouterUtils.formatTimestamp Date conversion error", err);
        return null;
    }
};
/**
 * Validate and return timezone (it is possible to use _ symbol instead of URL encoded / symbol)
 */
RopidRouterUtils.getPreferredTimezone = (preferredTimezone) => {
    const timezone = typeof preferredTimezone === "string"
        ? preferredTimezone.replace(/_/s, "/")
        : config_1.config.vehiclePositions.defaultTimezone;
    return timezone;
};
/**
 * Convert query parameter to array  string | ParsedQs | (string | ParsedQs)[] | undefined
 */
RopidRouterUtils.convertParamToArray = (param) => {
    if (!param)
        return [];
    if (Array.isArray(param)) {
        return param;
    }
    return [param];
};
//# sourceMappingURL=RopidRouterUtils.js.map