#!/bin/bash

echo "Starting Kniha Jízd Application (Local Mode)..."

if [ ! -f backend/.env ]; then
    echo "Creating .env file from example..."
    cp backend/.env.example backend/.env
    echo "⚠️  Please edit backend/.env with your credentials!"
    exit 1
fi

# Set environment variable for local development
export NEXT_PUBLIC_API_URL="http://100.110.142.68:8002"

echo "Starting Backend on port 8002..."
cd backend
python -m uvicorn api.main:app --reload --host 0.0.0.0 --port 8002 &
BACKEND_PID=$!

echo "Starting Frontend on port 3000..."
cd ../frontend
npm run dev &
FRONTEND_PID=$!

echo ""
echo "✅ Application started!"
echo "📊 Frontend: http://100.110.142.68:3000"
echo "🔧 Backend API: http://100.110.142.68:8002"
echo "📖 API Docs: http://100.110.142.68:8002/docs"
echo ""
echo "Accessible via Tailscale network at above URLs"
echo "Press Ctrl+C to stop..."

trap "kill $BACKEND_PID $FRONTEND_PID 2>/dev/null" EXIT
wait
