#!/bin/bash

# FuzyonLazer Setup Script

echo "Setting up FuzyonLazer application..."

# Check if MySQL is running
echo "Checking MySQL connection..."
mysql -u root -e "SELECT 1" >/dev/null 2>&1
if [ $? -ne 0 ]; then
    echo "MySQL is not running. Please start MySQL and try again."
    exit 1
fi

# Create database if it doesn't exist
echo "Creating database if it doesn't exist..."
mysql -u root -e "CREATE DATABASE IF NOT EXISTS fuzyonlazer;"

# Run migrations
echo "Running database migrations..."
php artisan migrate

# Seed the database
echo "Seeding the database..."
php artisan db:seed

# Create super admin user
echo "Creating super admin user..."
php artisan tinker --execute="
use App\Models\User;
use Illuminate\Support\Facades\Hash;
User::create([
    'name' => 'Admin',
    'email' => 'admin@fuzyonlazer.com',
    'password' => Hash::make('password'),
    'role' => 'super_admin'
]);
"

echo "Setup complete!"
echo "You can now start the application with: php artisan serve"
echo "Access the admin panel at: http://localhost:8000/admin"
echo "Login with: admin@fuzyonlazer.com / password"