#!/bin/bash

echo "🚀 Deploy completo: Orçamentos com Subcategorias"
echo ""

# === BACKEND ===
echo "📦 Enviando backend..."

sshpass -p 'Master9354' scp -o StrictHostKeyChecking=no \
  backend/database/migrations/2025_12_16_211102_add_subcategory_to_budgets_table.php \
  root@213.165.93.60:/var/www/webmoney/backend/database/migrations/

sshpass -p 'Master9354' scp -o StrictHostKeyChecking=no \
  backend/app/Models/Budget.php \
  root@213.165.93.60:/var/www/webmoney/backend/app/Models/

sshpass -p 'Master9354' scp -o StrictHostKeyChecking=no \
  backend/app/Http/Controllers/Api/BudgetController.php \
  root@213.165.93.60:/var/www/webmoney/backend/app/Http/Controllers/Api/

echo "✅ Arquivos backend enviados"
echo ""

echo "🔄 Executando migration..."
sshpass -p 'Master9354' ssh -o StrictHostKeyChecking=no root@213.165.93.60 \
  "cd /var/www/webmoney/backend && php artisan migrate --force"
echo ""

echo "🧹 Limpando cache..."
sshpass -p 'Master9354' ssh -o StrictHostKeyChecking=no root@213.165.93.60 \
  "cd /var/www/webmoney/backend && php artisan config:clear && php artisan cache:clear && php artisan route:clear"
echo ""

# === FRONTEND ===
echo "📦 Deploy frontend..."
cd frontend && ./deploy.sh

echo ""
echo "✅ Deploy completo!"
echo "🌐 Acesse: https://webmoney.cnxifly.com"
