import test from 'node:test';
import assert from 'node:assert/strict';

import { shouldPersistRemoteOverview } from './product-overview-persistence';

test('does not persist an empty remote overview', () => {
  assert.equal(shouldPersistRemoteOverview([]), false);
});

test('does not persist product-only remote overview', () => {
  assert.equal(shouldPersistRemoteOverview([{ id: 'product-1' }]), false);
});

test('does not persist relational products without frontend project or version data', () => {
  assert.equal(
    shouldPersistRemoteOverview([
      {
        id: 'cmqs07s3900001450gwu9lesi',
        name: '测试AI任务拆解',
        projects: [],
        versions: [],
        _count: { requirements: 0, projects: 0, versions: 0 },
      },
    ]),
    false,
  );
});

test('persists overview with frontend project and version ids', () => {
  assert.equal(
    shouldPersistRemoteOverview([
      {
        id: 'local-1782301366735',
        name: '测试AI任务拆解',
        projects: [{ id: 'proj-1782301375710', name: '任务拆解' }],
        versions: [{ id: 'ver-1782301431670', name: '任务拆解V1.0', status: 'developing' }],
      },
    ]),
    true,
  );
});
