"use strict";
/**
 * Timer System - Delay calculation module
 *
 * Calculates realistic response delays including:
 * - Configurable base delay range
 * - Typing duration based on message length
 * - Night time multiplier for slower responses during night hours
 *
 * Requirements: 5.1, 5.5
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.DEFAULT_TIMER_CONFIG = void 0;
exports.isNightTime = isNightTime;
exports.calculateTypingDuration = calculateTypingDuration;
exports.calculateDelay = calculateDelay;
exports.DEFAULT_TIMER_CONFIG = {
    baseDelay: { min: 5, max: 30 },
    busyScenarioDelay: { min: 15, max: 45 },
    typingSpeedCps: 5,
    nightHours: { start: 23, end: 7 },
    nightMultiplier: 2.5,
};
/**
 * Returns a random number between min and max (inclusive).
 */
function randomBetween(min, max) {
    return min + Math.random() * (max - min);
}
/**
 * Checks if the given hour falls within night hours.
 * Night hours wrap around midnight (e.g., 23:00 to 07:00).
 */
function isNightTime(hour, config) {
    const { start, end } = config.nightHours;
    if (start > end) {
        // Wraps around midnight: e.g., 23-07 means hour >= 23 OR hour < 7
        return hour >= start || hour < end;
    }
    // Non-wrapping range: e.g., 1-5 means hour >= 1 AND hour < 5
    return hour >= start && hour < end;
}
/**
 * Calculates typing animation duration based on message length and typing speed.
 * Returns duration in seconds.
 */
function calculateTypingDuration(messageLength, cps) {
    if (messageLength <= 0)
        return 0;
    if (cps <= 0)
        return 0;
    return messageLength / cps;
}
/**
 * Calculates total response delay in seconds.
 *
 * Total delay = base delay (with optional night multiplier) + typing duration
 */
function calculateDelay(config, messageLength, hour) {
    let delay = randomBetween(config.baseDelay.min, config.baseDelay.max);
    if (isNightTime(hour, config)) {
        delay *= config.nightMultiplier;
    }
    const typingDuration = calculateTypingDuration(messageLength, config.typingSpeedCps);
    return delay + typingDuration;
}
//# sourceMappingURL=index.js.map