<?php

require_once __DIR__ . '/../../config/helpers.php';
handleCors();

$route = getApiRouteSegments();
$resource = strtolower($route[0] ?? '');
$section = strtolower($route[1] ?? '');

if ($resource !== 'admin') {
    jsonResponse(false, 'Admin route not found', ['resource' => $resource, 'section' => $section, 'segments' => $route], 404);
}

switch ($section) {
    case 'users':
        require __DIR__ . '/Users/index.php';
        break;
    case 'mailboxes':
        require __DIR__ . '/Mailboxes/index.php';
        break;
    default:
        jsonResponse(false, 'Admin route not found', ['resource' => $resource, 'section' => $section, 'segments' => $route], 404);
}
