<?php
/**
 * User Registration API
 */

require_once __DIR__ . '/../includes/config.php';
require_once __DIR__ . '/../classes/Database.php';
require_once __DIR__ . '/../classes/Auth.php';
require_once __DIR__ . '/middleware.php';

$method = $_SERVER['REQUEST_METHOD'];

if ($method === 'POST') {
    $data = getJsonBody();
    validateRequired($data, ['first_name', 'last_name', 'email', 'phone', 'password', 'role_id']);
    
    $auth = new Auth();
    
    try {
        $userId = $auth->register($data);
        sendResponse(['user_id' => $userId, 'message' => 'User registered successfully']);
    } catch (Exception $e) {
        sendError($e->getMessage(), 400);
    }
} else {
    sendError('Method not allowed', 405);
}
?>
