#!/bin/bash

# MiMSMS Voter System - Quick Setup Script
# Run this script after uploading to cPanel

echo "=========================================="
echo "MiMSMS Voter System - Setup Script"
echo "=========================================="
echo ""

# Check if .env exists
if [ ! -f .env ]; then
    echo "Creating .env file from .env.example..."
    cp .env.example .env
    echo "✓ .env file created"
else
    echo "✓ .env file already exists"
fi

# Generate APP_KEY if not set
if grep -q "APP_KEY=$" .env; then
    echo "Generating APP_KEY..."
    php artisan key:generate
    echo "✓ APP_KEY generated"
else
    echo "✓ APP_KEY already set"
fi

# Set permissions
echo "Setting file permissions..."
chmod -R 755 storage
chmod -R 755 bootstrap/cache
chmod -R 777 storage
chmod -R 777 bootstrap/cache
echo "✓ Permissions set"

# Run migrations
echo ""
echo "Running database migrations..."
php artisan migrate --force
echo "✓ Migrations completed"

echo ""
echo "=========================================="
echo "Setup Complete!"
echo "=========================================="
echo ""
echo "Next steps:"
echo "1. Edit .env file with your database credentials"
echo "2. Edit .env file with your WHMCS API credentials"
echo "3. Create an admin user using: php artisan tinker"
echo "4. Visit your domain to access the system"
echo ""
