#!/bin/bash
# setup_fase2_3.sh
# Script para aplicar os arquivos da Fase 2 e 3 no repositório
# Execute na raiz do projeto: bash setup_fase2_3.sh

set -e

echo "🚀 Aplicando Fases 2 e 3 — Gade Logística"
echo ""

# Criar estrutura de diretórios necessários
mkdir -p app/controllers/users
mkdir -p app/views/devise/sessions
mkdir -p app/views/usuarios
mkdir -p app/views/configuracoes
mkdir -p app/views/dashboard
mkdir -p app/views/motorista
mkdir -p app/views/shared
mkdir -p app/views/layouts

echo "📁 Diretórios criados"

# Gerar timestamp para a migration
TIMESTAMP=$(date +%Y%m%d%H%M%S)
MIGRATION_FILE="db/migrate/${TIMESTAMP}_add_fase2_fields_to_users.rb"

# Verificar se a migration já existe
if ls db/migrate/*add_fase2_fields_to_users.rb 2>/dev/null; then
  echo "⚠️  Migration AddFase2FieldsToUsers já existe — pulando."
else
  cp db/migrate/20260610_add_fase2_fields_to_users.rb "$MIGRATION_FILE"
  echo "✅ Migration criada: $MIGRATION_FILE"
fi

echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "Próximos passos:"
echo ""
echo "  1. Rodar migrations:"
echo "     docker-compose exec app bundle exec rails db:migrate"
echo ""
echo "  2. Rodar seeds:"
echo "     docker-compose exec app bundle exec rails db:seed"
echo ""
echo "  3. Verificar rotas:"
echo "     docker-compose exec app bundle exec rails routes | grep -E 'usuario|config|dashboard|motor'"
echo ""
echo "  4. Subir servidor:"
echo "     docker-compose up -d && docker-compose logs -f app"
echo ""
echo "  Acesso:"
echo "  - Admin:     http://localhost:3000 → admin@gade.com / Gade@2026!"
echo "  - Motorista: http://localhost:3000 → aba PIN → 1234"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
