// Child process: serves a synthetic catalog. Prints the URL on stdout when ready.
import { startMockMagento } from '../mock-magento.js'
import { largeCatalog } from './large-catalog.js'

const data = largeCatalog(Number(process.argv[2] ?? 50_000))
const mock = await startMockMagento(data)
process.stdout.write(`${JSON.stringify({ url: mock.url, token: mock.token, products: data.products.length, sourceItems: data.sourceItems.length })}\n`)
process.on('message', (msg: { touch?: number }) => {
  // Simulate merchandisers editing N products "now", for the incremental-sync measurement.
  const now = new Date().toISOString().slice(0, 19).replace('T', ' ')
  for (const p of data.products.slice(0, msg.touch ?? 0)) p.updated_at = now
  process.send?.('touched')
})
