import { MessageRepo } from '../../../../../src/modules/netaclaw/runtime/weixin_db/message_repo.js';
import { existsSync } from 'node:fs';
import * as path from 'node:path';

const FIXTURE = path.resolve(__dirname, '../../../../../poc/weixin-4x/message_0_decrypted.db');

(existsSync(FIXTURE) ? describe : describe.skip)('MessageRepo (integration)', () => {
  it('lists Msg tables from decrypted DB', () => {
    const repo = new MessageRepo(FIXTURE);
    try {
      const tables = repo.listMsgTables();
      expect(tables.length).toBeGreaterThan(0);
      expect(tables.every(t => t.startsWith('Msg_'))).toBe(true);
    } finally {
      repo.close();
    }
  });

  it('maxCreateTime returns non-negative number', () => {
    const repo = new MessageRepo(FIXTURE);
    try {
      const tables = repo.listMsgTables();
      if (tables.length === 0) return;
      const ts = repo.maxCreateTime(tables[0]);
      expect(typeof ts).toBe('number');
      expect(ts).toBeGreaterThanOrEqual(0);
    } finally {
      repo.close();
    }
  });
});
