<?php
session_start();
require_once __DIR__ . '/core/db_connect.php';

if (!isset($_SESSION['user_id'])) {
  header('Location: login.php');
  exit;
}

$userId = (int)$_SESSION['user_id'];
$stmt = $conn_rbe->prepare("SELECT role FROM rbe_roles WHERE user_id = ? LIMIT 1");
$stmt->execute([$userId]);
$role = $stmt->fetchColumn();

switch ($role) {
  case 'admin':    header("Location: admin-dashboard.php"); break;
  case 'landlord': header("Location: landlord-dashboard.php"); break;
  case 'tenant':   header("Location: tenant-dashboard.php"); break;
  case 'agent':    header("Location: agents/dashboard.php"); break;
  default:         header("Location: login.php"); break;
}
exit;
