<?php
session_start();
require_once __DIR__ . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'database.php';
require_once __DIR__ . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';

if (!isInstalled()) {
    redirect('/install/');
}

$auth = new Auth();

if ($auth->check()) {
    switch ($auth->userRole()) {
        case 'super_admin':
            redirect('/admin/');
            break;
        case 'restaurant_admin':
            redirect('/restaurant-admin/');
            break;
        case 'kitchen_staff':
            redirect('/kitchen/');
            break;
        case 'waiter':
            redirect('/waiter/');
            break;
        case 'cashier':
            redirect('/cashier/');
            break;
        default:
            $auth->logout();
            redirect('/login.php');
            break;
    }
}

require_once __DIR__ . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR . 'index.php';
