"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const vitest_1 = require("vitest");
const index_js_1 = require("./index.js");
(0, vitest_1.describe)('Timer System', () => {
    (0, vitest_1.describe)('DEFAULT_TIMER_CONFIG', () => {
        (0, vitest_1.it)('should have sensible default values', () => {
            (0, vitest_1.expect)(index_js_1.DEFAULT_TIMER_CONFIG.baseDelay.min).toBe(5);
            (0, vitest_1.expect)(index_js_1.DEFAULT_TIMER_CONFIG.baseDelay.max).toBe(30);
            (0, vitest_1.expect)(index_js_1.DEFAULT_TIMER_CONFIG.typingSpeedCps).toBe(5);
            (0, vitest_1.expect)(index_js_1.DEFAULT_TIMER_CONFIG.nightHours.start).toBe(23);
            (0, vitest_1.expect)(index_js_1.DEFAULT_TIMER_CONFIG.nightHours.end).toBe(7);
            (0, vitest_1.expect)(index_js_1.DEFAULT_TIMER_CONFIG.nightMultiplier).toBe(2.5);
        });
    });
    (0, vitest_1.describe)('isNightTime', () => {
        const config = index_js_1.DEFAULT_TIMER_CONFIG;
        (0, vitest_1.it)('should return true for hours within night range (wrapping midnight)', () => {
            (0, vitest_1.expect)((0, index_js_1.isNightTime)(23, config)).toBe(true);
            (0, vitest_1.expect)((0, index_js_1.isNightTime)(0, config)).toBe(true);
            (0, vitest_1.expect)((0, index_js_1.isNightTime)(3, config)).toBe(true);
            (0, vitest_1.expect)((0, index_js_1.isNightTime)(6, config)).toBe(true);
        });
        (0, vitest_1.it)('should return false for daytime hours', () => {
            (0, vitest_1.expect)((0, index_js_1.isNightTime)(7, config)).toBe(false);
            (0, vitest_1.expect)((0, index_js_1.isNightTime)(12, config)).toBe(false);
            (0, vitest_1.expect)((0, index_js_1.isNightTime)(18, config)).toBe(false);
            (0, vitest_1.expect)((0, index_js_1.isNightTime)(22, config)).toBe(false);
        });
        (0, vitest_1.it)('should handle non-wrapping night range', () => {
            const nonWrapConfig = {
                ...config,
                nightHours: { start: 1, end: 5 },
            };
            (0, vitest_1.expect)((0, index_js_1.isNightTime)(0, nonWrapConfig)).toBe(false);
            (0, vitest_1.expect)((0, index_js_1.isNightTime)(1, nonWrapConfig)).toBe(true);
            (0, vitest_1.expect)((0, index_js_1.isNightTime)(3, nonWrapConfig)).toBe(true);
            (0, vitest_1.expect)((0, index_js_1.isNightTime)(5, nonWrapConfig)).toBe(false);
        });
        (0, vitest_1.it)('should handle edge at start boundary', () => {
            (0, vitest_1.expect)((0, index_js_1.isNightTime)(23, config)).toBe(true);
        });
        (0, vitest_1.it)('should handle edge at end boundary', () => {
            // end=7 means hour < 7 is night, hour=7 is NOT night
            (0, vitest_1.expect)((0, index_js_1.isNightTime)(7, config)).toBe(false);
        });
    });
    (0, vitest_1.describe)('calculateTypingDuration', () => {
        (0, vitest_1.it)('should calculate duration based on message length and cps', () => {
            (0, vitest_1.expect)((0, index_js_1.calculateTypingDuration)(50, 5)).toBe(10);
            (0, vitest_1.expect)((0, index_js_1.calculateTypingDuration)(100, 10)).toBe(10);
            (0, vitest_1.expect)((0, index_js_1.calculateTypingDuration)(25, 5)).toBe(5);
        });
        (0, vitest_1.it)('should return 0 for empty messages', () => {
            (0, vitest_1.expect)((0, index_js_1.calculateTypingDuration)(0, 5)).toBe(0);
        });
        (0, vitest_1.it)('should return 0 for negative message length', () => {
            (0, vitest_1.expect)((0, index_js_1.calculateTypingDuration)(-10, 5)).toBe(0);
        });
        (0, vitest_1.it)('should return 0 for zero or negative cps', () => {
            (0, vitest_1.expect)((0, index_js_1.calculateTypingDuration)(50, 0)).toBe(0);
            (0, vitest_1.expect)((0, index_js_1.calculateTypingDuration)(50, -1)).toBe(0);
        });
    });
    (0, vitest_1.describe)('calculateDelay', () => {
        let mathRandomSpy;
        (0, vitest_1.beforeEach)(() => {
            // Fix Math.random to return 0.5 for deterministic tests
            mathRandomSpy = vitest_1.vi.spyOn(Math, 'random').mockReturnValue(0.5);
        });
        (0, vitest_1.afterEach)(() => {
            mathRandomSpy.mockRestore();
        });
        (0, vitest_1.it)('should calculate delay with base + typing duration during daytime', () => {
            const config = index_js_1.DEFAULT_TIMER_CONFIG;
            // random=0.5 → base = 5 + 0.5*(30-5) = 17.5
            // typing = 50/5 = 10
            // total = 17.5 + 10 = 27.5
            const delay = (0, index_js_1.calculateDelay)(config, 50, 12);
            (0, vitest_1.expect)(delay).toBe(27.5);
        });
        (0, vitest_1.it)('should apply night multiplier during night hours', () => {
            const config = index_js_1.DEFAULT_TIMER_CONFIG;
            // random=0.5 → base = 5 + 0.5*(30-5) = 17.5
            // night multiplier: 17.5 * 2.5 = 43.75
            // typing = 50/5 = 10
            // total = 43.75 + 10 = 53.75
            const delay = (0, index_js_1.calculateDelay)(config, 50, 2);
            (0, vitest_1.expect)(delay).toBe(53.75);
        });
        (0, vitest_1.it)('should return only base delay for zero-length messages', () => {
            const config = index_js_1.DEFAULT_TIMER_CONFIG;
            // random=0.5 → base = 17.5, typing = 0
            const delay = (0, index_js_1.calculateDelay)(config, 0, 12);
            (0, vitest_1.expect)(delay).toBe(17.5);
        });
        (0, vitest_1.it)('should respect custom config values', () => {
            const config = {
                baseDelay: { min: 10, max: 20 },
                busyScenarioDelay: { min: 5, max: 15 },
                typingSpeedCps: 10,
                nightHours: { start: 22, end: 6 },
                nightMultiplier: 3,
            };
            // random=0.5 → base = 10 + 0.5*(20-10) = 15
            // daytime (hour=12): no multiplier
            // typing = 100/10 = 10
            // total = 15 + 10 = 25
            const delay = (0, index_js_1.calculateDelay)(config, 100, 12);
            (0, vitest_1.expect)(delay).toBe(25);
        });
        (0, vitest_1.it)('should produce delay within expected bounds', () => {
            mathRandomSpy.mockRestore();
            const config = index_js_1.DEFAULT_TIMER_CONFIG;
            const messageLength = 50;
            const typingDuration = messageLength / config.typingSpeedCps;
            for (let i = 0; i < 100; i++) {
                const delay = (0, index_js_1.calculateDelay)(config, messageLength, 12);
                (0, vitest_1.expect)(delay).toBeGreaterThanOrEqual(config.baseDelay.min + typingDuration);
                (0, vitest_1.expect)(delay).toBeLessThanOrEqual(config.baseDelay.max + typingDuration);
            }
        });
        (0, vitest_1.it)('should produce night delay within expected bounds', () => {
            mathRandomSpy.mockRestore();
            const config = index_js_1.DEFAULT_TIMER_CONFIG;
            const messageLength = 50;
            const typingDuration = messageLength / config.typingSpeedCps;
            const nightMin = config.baseDelay.min * config.nightMultiplier + typingDuration;
            const nightMax = config.baseDelay.max * config.nightMultiplier + typingDuration;
            for (let i = 0; i < 100; i++) {
                const delay = (0, index_js_1.calculateDelay)(config, messageLength, 2);
                (0, vitest_1.expect)(delay).toBeGreaterThanOrEqual(nightMin);
                (0, vitest_1.expect)(delay).toBeLessThanOrEqual(nightMax);
            }
        });
    });
});
//# sourceMappingURL=index.test.js.map