import dotenv from "dotenv";

dotenv.config({
  path: new URL("../../../apps/server/.env", import.meta.url).pathname,
});

import { db } from "./index";
import { seed } from "./seed";

async function seedIfEmpty() {
  const existingUser = await db.query.user.findFirst({
    columns: {
      id: true,
    },
  });

  if (existingUser) {
    console.info("Database already has users; skipping sample seed.");
    return;
  }

  await seed();
  console.info("Seeded auth admin and monitoring dashboard sample data.");
  console.info("Admin login: admin@minmon.local / admin12345");
}

seedIfEmpty()
  .then(() => {
    process.exit(0);
  })
  .catch((error) => {
    console.error("Failed to initialize seed data.", error);
    process.exit(1);
  });
