"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const const_1 = require("../../../../../../../const");
/*  In some cases both position and positionToUpdate are checked for values.
 *  If position state is 'input' then expect value in positionToUpdate instance.
 *  If position was already processed positionToUpdate is null so position instance should be checked.
 */
class AbstractDelayAtStop {
    calcDelayAtStop(actualTimestamp, scheduledTimestamp) {
        if (!scheduledTimestamp) {
            return null;
        }
        return (actualTimestamp - scheduledTimestamp.getTime()) / 1000;
    }
    resetContext(context, positionToUpdate, position) {
        if (this.isContextChange(context, positionToUpdate, position)) {
            context.lastPositionLastStop.arrival_time = null;
            context.lastPositionLastStop.arrival_delay = null;
            context.lastPositionLastStop.sequence = null;
            context.lastPositionLastStop.departure_time = null;
            context.lastPositionLastStop.departure_delay = null;
        }
        return context;
    }
    isContextChange(context, positionToUpdate, position) {
        return context.lastPositionLastStop.sequence !== (positionToUpdate?.last_stop_sequence ?? position?.last_stop_sequence);
    }
    didVehicleArriveAtTheLastStop(positionToUpdate, context) {
        return (positionToUpdate.state_position === const_1.StatePositionEnum.AFTER_TRACK_DELAYED &&
            context.lastPositionLastStop.arrival_delay === null);
    }
    isValidUntrackedPosition(positionToUpdate) {
        return (positionToUpdate.state_position === const_1.StatePositionEnum.AFTER_TRACK ||
            positionToUpdate.state_position === const_1.StatePositionEnum.AFTER_TRACK_DELAYED);
    }
}
exports.default = AbstractDelayAtStop;
//# sourceMappingURL=AbstractDelayAtStop.js.map