#!/bin/bash

echo "Starting Kniha Jízd Application..."

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

if [ "$1" == "docker" ]; then
    echo "Starting with Docker Compose..."
    docker-compose up --build
else
    echo "Starting Backend (FastAPI)..."
    cd backend
    python -m uvicorn api.main:app --reload --host 0.0.0.0 --port 8002 &
    BACKEND_PID=$!

    echo "Starting Frontend (Next.js)..."
    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 "Press Ctrl+C to stop..."

    trap "kill $BACKEND_PID $FRONTEND_PID" EXIT
    wait
fi
