#!/bin/bash

# Samir Portal Setup Script
# This script will set up the database and create default users

echo "🚀 Setting up Samir Portal..."
echo ""

# Change to project directory
cd "$(dirname "$0")"

# PHP path
PHP_PATH="/Applications/MAMP/bin/php/php8.4.1/bin/php"

# Check if PHP exists
if [ ! -f "$PHP_PATH" ]; then
    echo "❌ PHP not found at $PHP_PATH"
    echo "Please update the PHP_PATH in this script to match your MAMP installation"
    exit 1
fi

echo "📦 Running migrations..."
$PHP_PATH artisan migrate --force

if [ $? -ne 0 ]; then
    echo "❌ Migrations failed. Please check your database connection in .env"
    exit 1
fi

echo ""
echo "🌱 Seeding database with default users..."
$PHP_PATH artisan db:seed --force

if [ $? -ne 0 ]; then
    echo "❌ Seeding failed"
    exit 1
fi

echo ""
echo "🔗 Creating storage link..."
$PHP_PATH artisan storage:link

echo ""
echo "✅ Setup complete!"
echo ""
echo "📧 Default Login Credentials:"
echo "   Admin:    admin@samirportal.com / password"
echo "   Employee: employee@samirportal.com / password"
echo "   Customer: customer@samirportal.com / password"
echo ""
echo "🌐 Access the portal at: http://localhost:8000/login"
echo ""
