import { assert, createLogicSuite } from '@genesislcap/foundation-testing';
import { appendCostSessionRecord, clearCostSessionHistory, costHistoryStorageKey, formatCostSessionDate, loadCostSessionHistory, removeCostSessionRecord, saveCostSessionHistory, } from './cost-session-history';
const scope = `test-${Date.now()}`;
const sampleRecord = (overrides = {}) => (Object.assign({ id: 'rec-1', title: 'Equity Options Pricer', endedAt: '2026-06-14T12:00:00.000Z', costUsd: 1.86, tokensConsumed: 1400000, models: [{ model: 'claude-sonnet-4-6', provider: 'anthropic' }] }, overrides));
const suite = createLogicSuite('costSessionHistory');
suite('uses a scoped storage key', () => {
    assert.is(costHistoryStorageKey('my-app'), 'genesis-ai-assistant:cost-history:my-app');
});
suite('persists and loads records newest-first via append', () => {
    var _a, _b;
    clearCostSessionHistory(scope);
    appendCostSessionRecord(scope, sampleRecord({ id: 'a', title: 'First' }));
    appendCostSessionRecord(scope, sampleRecord({ id: 'b', title: 'Second' }));
    const loaded = loadCostSessionHistory(scope);
    assert.is(loaded.length, 2);
    assert.is((_a = loaded[0]) === null || _a === void 0 ? void 0 : _a.id, 'b');
    assert.is((_b = loaded[1]) === null || _b === void 0 ? void 0 : _b.id, 'a');
    clearCostSessionHistory(scope);
});
suite('removes one record by id', () => {
    var _a;
    clearCostSessionHistory(scope);
    saveCostSessionHistory(scope, [sampleRecord({ id: 'keep' }), sampleRecord({ id: 'drop' })]);
    const remaining = removeCostSessionRecord(scope, 'drop');
    assert.is(remaining.length, 1);
    assert.is((_a = remaining[0]) === null || _a === void 0 ? void 0 : _a.id, 'keep');
    clearCostSessionHistory(scope);
});
suite('formats session dates for display', () => {
    assert.is(formatCostSessionDate('2026-06-14T12:00:00.000Z'), 'Jun 14, 2026');
});
suite.run();
