#!/bin/bash

echo "=========================================="
echo "  SeacotexCommercial Setup"
echo "=========================================="

# Fix: Mark the existing invoices migration as completed
echo "Fixing migration records..."
php artisan tinker --execute="
if (!DB::table('migrations')->where('migration', '2025_11_26_001359_create_invoices_table')->exists()) {
    DB::table('migrations')->insert(['migration' => '2025_11_26_001359_create_invoices_table', 'batch' => 1]);
    echo 'Migration record added.';
} else {
    echo 'Migration record already exists.';
}
"

# Run any pending migrations
echo ""
echo "Running migrations..."
php artisan migrate --force

# Check if admin user needed
echo ""
echo "=========================================="
echo "  Create Admin User (if needed)"
echo "=========================================="
php artisan make:filament-user

# Start server
echo ""
echo "=========================================="
echo "  Starting Server"
echo "=========================================="
echo "App URL: http://127.0.0.1:8000"
echo "Admin Panel: http://127.0.0.1:8000/admin"
echo "=========================================="
php artisan serve