#!/bin/bash

# Kill processes by port (backend 5000, selenium 5002, patient extractor 5001, payment OCR 5003, frontend 3000/3001)
for PORT in 5000 5001 5002 5003 3000 3001; do
  PIDS=$(lsof -ti :$PORT 2>/dev/null)
  if [ -n "$PIDS" ]; then
    echo "Killing port $PORT (PID $PIDS)"
    kill -9 $PIDS 2>/dev/null
  fi
done

# Kill any remaining turbo / ts-node-dev / vite processes for this project
PROJECT="DentalManagementMH06"
pkill -9 -f "turbo.*$PROJECT" 2>/dev/null
pkill -9 -f "ts-node-dev.*$PROJECT" 2>/dev/null
pkill -9 -f "vite.*$PROJECT" 2>/dev/null
pkill -9 -f "agent.py" 2>/dev/null

echo "All Dental App processes stopped."
