#!/bin/bash
# Deploy Document Intelligence API to VPS
# Run from: /home/ubuntu/docintell-api/

set -e

echo "=== Document Intelligence API Deployment ==="

# 1. Build and start container
echo "1. Building Docker image..."
docker compose build

echo "2. Starting container..."
docker compose up -d

echo "3. Checking container health..."
sleep 5
docker compose ps
docker compose logs --tail=20

# 4. Test API
echo "4. Testing API..."
curl -s http://localhost:8002/health | jq .

echo ""
echo "=== Container deployed successfully ==="
echo ""
echo "Next steps:"
echo "1. Set up nginx config:"
echo "   sudo cp deploy/nginx-ai.glocalis.com.conf /etc/nginx/sites-available/ai.glocalis.com"
echo "   sudo ln -sf /etc/nginx/sites-available/ai.glocalis.com /etc/nginx/sites-enabled/"
echo ""
echo "2. Get SSL certificate (run without ssl first):"
echo "   # First, create temp config without SSL:"
echo "   sudo nano /etc/nginx/sites-available/ai.glocalis.com"
echo "   # Comment out the ssl server block, keep only port 80"
echo "   sudo nginx -t && sudo systemctl reload nginx"
echo "   sudo certbot --nginx -d ai.glocalis.com"
echo ""
echo "3. Verify:"
echo "   curl https://ai.glocalis.com/health"
