"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CommonRunHelper = void 0;
const Di_1 = require("../../../ioc/Di");
const ioc_1 = require("@golemio/core/dist/integration-engine/ioc");
class CommonRunHelper {
    constructor() {
        this.logger = Di_1.VPContainer.resolve(ioc_1.ContainerToken.Logger);
    }
    /**
     * @returns {ICommonRunIdentifiers | null} commonRunIdentifiers
     *  { runId: "123_456_789_2020-01-01T00:00:00Z", routeId: "123", runNumber: "456" }
     */
    getRunIdentifiers(properties, msgTimestamp) {
        const { turnus, evc } = properties;
        let identifiers = null;
        const [routeIdFromTurnus, runNumberFromTurnus] = turnus.split("/");
        if (routeIdFromTurnus && runNumberFromTurnus) {
            identifiers = {
                runId: `${routeIdFromTurnus}_${runNumberFromTurnus}_${evc}_${msgTimestamp}`,
                routeId: routeIdFromTurnus,
                runNumber: runNumberFromTurnus,
            };
        }
        return identifiers;
    }
    /**
     * @param {string} utcTimestamp - "2022-03-27T12:04:38"
     * @returns {Date | null} dateObject - Date(2022-03-27T12:04:38.000Z)
     */
    parseDateFromRunInput(utcTimestamp) {
        const date = new Date(utcTimestamp + "Z");
        if (date.toString() === "Invalid Date") {
            this.logger.info(`parseDateFromRunInput: unable to parse date from ${utcTimestamp + "Z"}`);
            return null;
        }
        return date;
    }
}
exports.CommonRunHelper = CommonRunHelper;
//# sourceMappingURL=CommonRunHelper.js.map