#!/bin/bash

echo "========================================"
echo "ML Model Docker Runner"
echo "========================================"
echo "This will start the ML model and connect to your existing MySQL"
echo

# Check if Docker Compose is available
if ! command -v docker-compose &> /dev/null; then
    echo "ERROR: Docker Compose is not installed or not in PATH"
    echo "Please install Docker Desktop which includes Docker Compose"
    echo "Or install docker-compose separately:"
    echo "  macOS: brew install docker-compose"
    echo "  Linux: sudo apt-get install docker-compose"
    exit 1
fi

# Stop and remove existing containers
echo "Stopping any existing containers..."
docker-compose down 2>/dev/null

# Remove existing images to ensure fresh build
echo "Removing existing images..."
docker rmi ml-model_ml-model 2>/dev/null

# Build and start the ML model
echo "Building and starting ML model..."
echo "Note: Connecting to remote MySQL database at 193.203.166.210:3306"
echo
docker-compose up --build

echo
echo "Container stopped. Press Enter to exit..."
read 