import { prisma } from './prisma';

export const SITE_SETTINGS_ID = 'singleton';
export const DEFAULT_MAINTENANCE_MESSAGE = "We're currently updating the site — back shortly!";

// Read-only — never writes on read, so it's cheap to call from the root layout
// on every request. The row is created/updated only from the admin maintenance
// action (upsert). Returns safe defaults when the row doesn't exist yet.
export async function getSiteSettings() {
  const row = await prisma.siteSetting.findUnique({ where: { id: SITE_SETTINGS_ID } });
  return {
    maintenanceMode: row?.maintenanceMode ?? false,
    maintenanceMessage: row?.maintenanceMessage ?? null,
  };
}
