/**
 * Seed a generic demo workspace for development/CI. Idempotent — does
 * nothing if any workspace already exists. Run via: `npm run db:seed-dev`.
 *
 * For integrators: do NOT run this in production. Use your CRM's admin UI
 * or the Mailforge Settings UI to create real workspaces.
 */

import { getAllWorkspaces, upsertWorkspace } from '@/lib/db/repositories';
import { getDemoWorkspaceSeed } from '@/lib/db/defaults';

function main(): void {
  const existing = getAllWorkspaces();
  if (existing.length > 0) {
    console.log(
      `[seed-dev] Skip — found ${existing.length} workspace(s) already: ${existing.map((w) => w.slug).join(', ')}`,
    );
    return;
  }

  const seed = getDemoWorkspaceSeed();
  const created = upsertWorkspace(seed);
  console.log(`[seed-dev] Created demo workspace "${created.slug}" (id=${created.id})`);
}

main();
