import { db } from "@/lib/db";

export type LandingMode = "open" | "exclusive";

/**
 * Read the current landing page mode from the SiteConfig singleton.
 * Defaults to "open" if no row exists yet (first boot / fresh DB).
 */
export async function getLandingMode(): Promise<LandingMode> {
  try {
    const config = await db.siteConfig.findUnique({
      where: { id: "singleton" },
    });
    if (config?.landingMode === "exclusive") return "exclusive";
    return "open";
  } catch {
    // DB not ready or table doesn't exist yet — safe default
    return "open";
  }
}
