#!/bin/bash

# Simple deployment script for API server
# This updates the API server code on EC2

API_SERVER_IP="3.71.161.51"
API_SERVER_URL="https://api.filamenteka.rs"

echo "🚀 Deploying API server updates..."

# Create a temporary deployment package
echo "📦 Creating deployment package..."
mkdir -p tmp-deploy
cp -r api/* tmp-deploy/
cp package.json tmp-deploy/
cp package-lock.json tmp-deploy/

# Create tarball
tar -czf api-deploy.tar.gz -C tmp-deploy .
rm -rf tmp-deploy

echo "📤 Package created: api-deploy.tar.gz"
echo ""
echo "⚠️  Manual deployment required:"
echo "1. Copy api-deploy.tar.gz to your server"
echo "2. SSH into the server at $API_SERVER_IP"
echo "3. Extract and restart the API service:"
echo "   tar -xzf api-deploy.tar.gz"
echo "   npm install --production"
echo "   sudo systemctl restart node-api"
echo ""
echo "4. Run database migration if needed:"
echo "   psql -U filamenteka_admin -d filamenteka < database/migrations/004_remove_brand_column.sql"

# Cleanup
rm -f api-deploy.tar.gz

echo ""
echo "✅ Deployment package instructions complete!"