/**
 * 로컬 DB가 비어 있을 때만 seed 실행 (최초 1회용)
 */
import 'dotenv/config';
import { execSync } from 'child_process';
import path from 'path';
import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient();

async function main() {
  const users = await prisma.user.count();
  if (users > 0) {
    console.log('✓ Local DB has data — skip initial seed');
    return;
  }

  console.log('📦 Empty local DB — loading initial sample data...');
  const backendRoot = path.resolve(__dirname, '..');
  execSync('tsx prisma/seed.ts', { stdio: 'inherit', cwd: backendRoot });
}

main()
  .catch((err) => {
    console.error(err);
    process.exit(1);
  })
  .finally(() => prisma.$disconnect());
