<?php
require_once 'controllers/AuthController.php';
require_once 'helpers/auth_helper.php';
require_once 'helpers/audit_trail.php';
require_once 'helpers/response_helper.php';

$authController = new AuthController();


// Special route for login (no auth required)
if ($method === 'POST' && $uri === '/login') {
    $data = json_decode(file_get_contents('php://input'), true);
    $response = $authController->login($data);
    $user_id = $response && is_string($response) ? (json_decode($response, true)['user']['user_id'] ?? null) : null;
    $user_type = $response && is_string($response) ? (json_decode($response, true)['user']['user_type'] ?? 'public') : 'public';
    logAndRespond($user_id, $user_type, '/login', $response, 'POST', $data);
    exit;
}


?>