<?php
// /elms/index.php — minimal, safe entrypoint
declare(strict_types=1);

if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

require_once __DIR__ . '/includes/helpers.php';
require_once __DIR__ . '/includes/auth.php';

$role = $_SESSION['admin_role']
    ?? ($_SESSION['user']['role'] ?? null)
    ?? ($_SESSION['role_code'] ?? null)
    ?? ($_SESSION['role'] ?? '');

$role = strtolower((string)$role);

switch ($role) {
    case 'super_admin':
    case 'admin':
    case 'manager':
        header('Location: ' . app_url('/admin/dashboard.php'));
        exit;

    case 'coordinator':
        header('Location: ' . app_url('/coordinator/dashboard.php'));
        exit;

    case 'lecturer':
        header('Location: ' . app_url('/lecturer/dashboard.php'));
        exit;

    case 'student':
        header('Location: ' . app_url('/student/modules.php'));
        exit;
}

header('Location: ' . app_url('/auth/login.php'));
exit;