#!/bin/bash

# Quick Start Script for Updated Training Interface

echo "=========================================="
echo "🚀 TRAINING INTERFACE - QUICK START"
echo "=========================================="
echo ""

# Check if conda is available
if ! command -v conda &> /dev/null; then
    echo "❌ Conda not found. Please install Anaconda/Miniconda first."
    exit 1
fi

echo "📦 Step 1: Activating conda environment..."
source $(conda info --base)/etc/profile.d/conda.sh
conda activate env_01

if [ $? -ne 0 ]; then
    echo "❌ Failed to activate env_01. Please check your conda environment."
    exit 1
fi

echo "✅ Environment activated: env_01"
echo ""

echo "📦 Step 2: Checking required packages..."
python -c "import geopandas; import fastapi; import uvicorn" 2>/dev/null

if [ $? -ne 0 ]; then
    echo "⚠️  Some packages are missing. Installing..."
    pip install geopandas fastapi uvicorn python-multipart
else
    echo "✅ All required packages installed"
fi
echo ""

echo "📦 Step 3: Checking training files..."
if [ -d "train" ]; then
    file_count=$(ls train/*.shp 2>/dev/null | wc -l)
    echo "✅ Found $file_count shapefile(s) in train/ directory"
    ls train/*.shp 2>/dev/null | while read file; do
        echo "   - $(basename $file)"
    done
else
    echo "⚠️  train/ directory not found. Creating..."
    mkdir -p train
fi
echo ""

echo "🌐 Step 4: Starting API Server..."
echo "   Server will be available at: http://localhost:8000"
echo "   Training interface: http://localhost:8000/training"
echo ""
echo "   Press Ctrl+C to stop the server"
echo ""
echo "=========================================="
echo ""

# Start the API server
python api_server.py
