import { PrismaClient } from "@prisma/client";

/**
 * Seeds a fresh database with ONLY the InstanceSettings singleton.
 *
 * Deliberately does NOT seed an admin user, default credentials, or
 * the curated exercise library. As of v1.0.0:4, fresh installs ship
 * with zero users — the operator must create the first admin via the
 * StartOS Action "Set admin credentials" before anyone can log in.
 *
 * Why: shipping a default `admin@local` / `workout123` is the kind of
 * footgun that turns into "default credential exposure" headlines for
 * any operator who forgets to rotate. Forcing the StartOS action up
 * front means there's literally no usable default to forget about.
 *
 * The curated exercise library still ships in
 * prisma/exercises.seed.json. It gets inserted for the admin at the
 * moment they're created (the StartOS action triggers
 * ensureExerciseLibrary right after the User INSERT) and then for
 * every subsequent user via the boot-time ensure step.
 *
 * Used at Docker build time to populate the empty-schema fallback DB
 * (the one that gets copied into /data on a brand-new sideload).
 */

const prisma = new PrismaClient();

async function main() {
  await prisma.instanceSettings.upsert({
    where: { id: 1 },
    update: {},
    create: { id: 1, signupsOpen: false },
  });
  console.log(
    "[seed] created InstanceSettings singleton (signupsOpen: false)",
  );
  console.log(
    "[seed] no users seeded — operator must run the StartOS Action " +
      "'Set admin credentials' to bootstrap the first admin",
  );
}

main()
  .then(async () => {
    await prisma.$disconnect();
  })
  .catch(async (e) => {
    console.error(e);
    await prisma.$disconnect();
    process.exit(1);
  });
