import { prisma } from "./prisma";

/**
 * Read the singleton InstanceSettings row, defensively creating it if
 * missing. The compat ALTERs in docker_entrypoint.sh insert this row at
 * boot time, but we still upsert here so that fresh dev installs (or
 * any boot path that didn't run the entrypoint) see something usable.
 */
export async function getInstanceSettings() {
  return prisma.instanceSettings.upsert({
    where: { id: 1 },
    update: {},
    create: { id: 1, signupsOpen: false },
  });
}

export async function setSignupsOpen(open: boolean) {
  return prisma.instanceSettings.upsert({
    where: { id: 1 },
    update: { signupsOpen: open },
    create: { id: 1, signupsOpen: open },
  });
}
