#!/bin/bash
# ============================================
# BraceIQMed - Local Update Script (Linux/Mac)
# Rebuilds and restarts Docker containers
# ============================================

set -e

echo "========================================"
echo "  BraceIQMed - Local Update"
echo "========================================"
echo ""

# Change to project directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
cd "$PROJECT_DIR"

echo "[1/3] Building Docker images..."
docker compose build

echo ""
echo "[2/3] Restarting containers..."
docker compose up -d

echo ""
echo "[3/3] Waiting for health checks..."
sleep 5

# Check health
echo ""
docker compose ps

echo ""
echo "========================================"
echo "  Update complete!"
echo "  App running at: http://localhost"
echo "========================================"
