import { buildCompileDoneEvent } from './src/server/routes/compile.js';

function assert(condition, message) {
  if (!condition) throw new Error(message);
}

console.log('\n── Compile Done Event ──');

const successEvent = buildCompileDoneEvent({
  data: {
    gid: 1655,
    appPreviewUrlMap: {
      TeacherPrepApp: 'https://v4pre.visuallogic.ai/play/eRMMkld2',
    },
  },
}, { success: true });

assert(successEvent.success === true, 'success event should preserve success=true');
assert(successEvent.gid === 1655, 'success event should include gid');
assert(successEvent.previewUrls.TeacherPrepApp, 'success event should include previewUrls');
assert(successEvent.errCount === 0, 'success event should default to zero errCount');

const errorEvent = buildCompileDoneEvent({
  data: { gid: 1655 },
}, { success: false, errors: [{ message: 'oops' }] });

assert(errorEvent.success === false, 'error event should preserve success=false');
assert(errorEvent.errCount === 1, 'error event should include errCount');
assert(Array.isArray(errorEvent.errors) && errorEvent.errors.length === 1, 'error event should include errors array');

console.log('PASS test-compile-done-event.js');
