"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
describe('TimeSaved', () => {
    let module;
    beforeEach(async () => {
        module = await Promise.resolve().then(() => __importStar(require('../../walls/03-knowledge/decisions/time-saved')));
        module.clearTimeSaved();
    });
    test('records a simple pattern acceptance', () => {
        const rec = module.recordTimeSaved({
            patternId: 'p1',
            category: 'variable_declaration',
            description: 'uses const',
            from: 'var x = 1',
            to: 'const x = 1',
            language: 'typescript',
        });
        expect(rec.patternId).toBe('p1');
        expect(rec.estimatedTimeSeconds).toBe(15);
    });
    test('estimates more time for complex patterns', () => {
        const complex = module.recordTimeSaved({
            patternId: 'p2',
            from: 'function a() {\n  let x = 1;\n  let y = 2;\n  let z = 3;\n  return x + y + z;\n}',
            to: 'function a() {\n  const x = 1;\n  const y = 2;\n  const z = 3;\n  return x + y + z;\n}',
        });
        expect(complex.estimatedTimeSeconds).toBe(120);
        const huge = module.recordTimeSaved({
            patternId: 'p3',
            from: Array(20).fill('line').join('\n'),
            to: Array(20).fill('line').join('\n'),
        });
        expect(huge.estimatedTimeSeconds).toBe(300);
    });
    test('getTimeSavedStats returns correct totals', () => {
        module.recordTimeSaved({ patternId: 'p1', category: 'a', from: 'x', to: 'y', language: 'ts' });
        module.recordTimeSaved({ patternId: 'p2', category: 'b', from: 'x', to: 'y', language: 'ts' });
        module.recordTimeSaved({ patternId: 'p1', category: 'a', from: 'x', to: 'y', language: 'js' });
        const stats = module.getTimeSavedStats();
        expect(stats.totalAcceptances).toBe(3);
        expect(stats.totalTimeSavedSeconds).toBe(45);
        expect(stats.perCategory.length).toBe(2);
        expect(stats.perLanguage.length).toBe(2);
        expect(stats.topPatterns.length).toBe(2);
    });
    test('getTimeSavedByPattern filters correctly', () => {
        module.recordTimeSaved({ patternId: 'p1', from: 'x', to: 'y' });
        module.recordTimeSaved({ patternId: 'p2', from: 'x', to: 'y' });
        module.recordTimeSaved({ patternId: 'p1', from: 'x', to: 'y' });
        const result = module.getTimeSavedByPattern('p1');
        expect(result.count).toBe(2);
        expect(result.totalSeconds).toBe(30);
    });
    test('clearTimeSaved resets all data', () => {
        module.recordTimeSaved({ patternId: 'p1', from: 'x', to: 'y' });
        expect(module.getTimeSavedStats().totalAcceptances).toBe(1);
        module.clearTimeSaved();
        expect(module.getTimeSavedStats().totalAcceptances).toBe(0);
    });
});
//# sourceMappingURL=time-saved.test.js.map