# Justfile for Post-ERG front-backend website

# Default recipe - show available commands
default:
    @just --list

# Start PHP development server
serve:
    @echo "Starting PHP development server on http://localhost:8000"
    @echo "Using database: ../formulaire/test.db"
    @echo "Press Ctrl+C to stop"
    @php -S 127.0.0.1:8000

# Test database connection
test:
    @echo "Testing database connection..."
    @php test_db.php

# Show database statistics
stats:
    @echo "=== Database Statistics ==="
    @sqlite3 ../formulaire/test.db "SELECT COUNT(*) || ' total theses' FROM theses;"
    @sqlite3 ../formulaire/test.db "SELECT COUNT(*) || ' published theses' FROM theses WHERE is_published = 1;"
    @sqlite3 ../formulaire/test.db "SELECT COUNT(*) || ' authors' FROM authors;"
    @sqlite3 ../formulaire/test.db "SELECT COUNT(*) || ' keywords' FROM keywords;"

# Show recent published theses
recent:
    @echo "=== Recent Published Theses ==="
    @sqlite3 -column -header ../formulaire/test.db "SELECT id, title, year, authors FROM v_theses_public ORDER BY year DESC, title LIMIT 10;"

# Query database interactively
query:
    @sqlite3 ../formulaire/test.db

# Show specific thesis details
show id:
    @sqlite3 -column -header ../formulaire/test.db "SELECT * FROM v_theses_full WHERE id = {{id}};"

# Check PHP syntax for all PHP files
check:
    @echo "Checking PHP syntax..."
    @php -l Database.php
    @php -l index.php
    @php -l memoire.php
    @php -l apropos.php
    @php -l contact.php
    @php -l licences.php
    @echo "✓ All files have valid syntax"

# View error log
logs:
    @if [ -f error.log ]; then tail -n 50 error.log; else echo "No error log found"; fi
