<?php
require_once 'config/cors.php';
require_once 'config/database.php';
require_once 'utils/helpers.php';

// Set the default timezone to UTC
date_default_timezone_set('UTC');

// Get the request URI
$request = isset($_GET['request']) ? $_GET['request'] : '';
$method = $_SERVER['REQUEST_METHOD'];

// Route the request
$routes = [
    'auth/register' => 'auth/register.php',
    'auth/verify' => 'auth/verify.php',
    'auth/complete-registration' => 'auth/complete-registration.php',
    'auth/login' => 'auth/login.php',
    'auth/logout' => 'auth/logout.php',
    'auth/roles' => 'auth/roles.php',
    'user/profile' => 'user/profile.php',
    'user/update' => 'user/update.php',
    'services/list' => 'services/list.php',
    'services/active' => 'services/active.php',
    'services/create' => 'services/create.php',
    'services/update' => 'services/update.php',
    'services/delete' => 'services/delete.php',
    'attendance/clock-in' => 'attendance/clock-in.php',
    'attendance/clock-out' => 'attendance/clock-out.php',
    'attendance/history' => 'attendance/history.php',
    'attendance/status' => 'attendance/status.php',
    'tickets/list' => 'tickets/list.php',
    'tickets/progress' => 'tickets/progress.php',
    'tickets/redeem' => 'tickets/redeem.php',
    'tickets/stats' => 'tickets/stats.php',
    'admin/login' => 'admin/login.php',
    'admin/users' => 'admin/users.php',
    'admin/departments' => 'admin/departments.php',
    'admin/roles' => 'admin/roles.php',
    'admin/services' => 'admin/services.php',
    'admin/service-types' => 'admin/service-types.php',
    'admin/service-templates' => 'admin/service-templates.php',
    'admin/service-occurrences' => 'admin/service-occurrences.php',
    'admin/attendance' => 'admin/attendance.php',
    'admin/rewards' => 'admin/rewards.php',
    'admin/tickets' => 'admin/tickets.php',
    'admin/reports' => 'admin/reports.php',
    'admin/dashboard' => 'admin/dashboard.php',
];

// Check if route exists
if (array_key_exists($request, $routes)) {
    require_once $routes[$request];
} else {
    Helpers::sendResponse(false, 'Endpoint not found', null, 404);
}
