#!/bin/bash

# Script para verificar referências à coluna 'active' inexistente

echo "========================================="
echo "Verificando referências à coluna 'active'"
echo "========================================="
echo ""

cd "$(dirname "$0")"

echo "1. Verificando Model Subscription.php..."
if grep -q "'active'" backend/app/Models/Subscription.php; then
    echo "   ❌ ENCONTRADO 'active' no Model!"
    grep -n "'active'" backend/app/Models/Subscription.php
else
    echo "   ✅ Model limpo"
fi
echo ""

echo "2. Verificando WebhookController.php..."
if grep -q "'active'" backend/app/Http/Controllers/Api/WebhookController.php; then
    echo "   ❌ ENCONTRADO 'active' no WebhookController!"
    grep -n "'active'" backend/app/Http/Controllers/Api/WebhookController.php | head -5
else
    echo "   ✅ WebhookController limpo"
fi
echo ""

echo "3. Verificando PaymentController.php..."
if grep -q "'active'" backend/app/Http/Controllers/Api/PaymentController.php; then
    echo "   ❌ ENCONTRADO 'active' no PaymentController!"
    grep -n "'active'" backend/app/Http/Controllers/Api/PaymentController.php
else
    echo "   ✅ PaymentController limpo"
fi
echo ""

echo "4. Verificando CheckPendingPayments.php..."
if grep -q "'active'" backend/app/Console/Commands/CheckPendingPayments.php; then
    echo "   ❌ ENCONTRADO 'active' no CheckPendingPayments!"
    grep -n "'active'" backend/app/Console/Commands/CheckPendingPayments.php | head -5
else
    echo "   ✅ CheckPendingPayments limpo"
fi
echo ""

echo "5. Verificando test_payment_flow.php..."
if grep -q "'active'" test_payment_flow.php; then
    echo "   ❌ ENCONTRADO 'active' no test_payment_flow!"
    grep -n "'active'" test_payment_flow.php | head -5
else
    echo "   ✅ test_payment_flow limpo"
fi
echo ""

echo "6. Verificando 'cancelled_at' (coluna também inexistente)..."
if grep -q "'cancelled_at'" test_payment_flow.php; then
    echo "   ❌ ENCONTRADO 'cancelled_at' no test_payment_flow!"
    grep -n "'cancelled_at'" test_payment_flow.php
fi

if grep -q "'cancelled_at'" backend/app/Http/Controllers/Api/WebhookController.php; then
    echo "   ❌ ENCONTRADO 'cancelled_at' no WebhookController!"
    grep -n "'cancelled_at'" backend/app/Http/Controllers/Api/WebhookController.php
fi

if grep -q "'cancelled_at'" backend/app/Console/Commands/CheckPendingPayments.php; then
    echo "   ❌ ENCONTRADO 'cancelled_at' no CheckPendingPayments!"
    grep -n "'cancelled_at'" backend/app/Console/Commands/CheckPendingPayments.php
fi
echo ""

echo "========================================="
echo "Verificação concluída!"
echo "========================================="
echo ""
echo "Se aparecer algum ❌ acima, o arquivo precisa ser corrigido."
echo "Se aparecer apenas ✅, os arquivos estão corretos."
