#!/bin/bash
# =============================================================================
# MOPC Platform - One-Time Database Seed
# =============================================================================
# Usage: ./scripts/seed.sh
# Run this ONCE after the first deployment to populate the database with:
#   - Super admin user
#   - System settings
#   - Program & Round 1 configuration
#   - Evaluation form
#   - Candidature data from CSV

set -e

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
DOCKER_DIR="$PROJECT_DIR/docker"

echo "============================================"
echo "  MOPC Platform - Database Seed"
echo "============================================"
echo ""
echo "This will seed the database with:"
echo "  - Admin user & system settings"
echo "  - Program, Round 1, evaluation form"
echo "  - Candidature data from CSV"
echo ""
read -p "Continue? (y/N) " -n 1 -r
echo ""

if [[ ! $REPLY =~ ^[Yy]$ ]]; then
    echo "Aborted."
    exit 0
fi

echo ""
echo "==> Running base seed (admin, settings, program, round, eval form)..."
cd "$DOCKER_DIR"
docker compose exec app npx tsx prisma/seed.ts

echo ""
echo "==> Running candidatures import from CSV..."
docker compose exec app npx tsx prisma/seed-candidatures.ts

echo ""
echo "============================================"
echo "  Seed complete!"
echo "============================================"
echo ""
echo "  Admin login: matt.ciaccio@gmail.com"
echo "  (Use magic link authentication)"
echo ""
