<?php

class UserController {

    // ─── GET /api/user/status ─────────────────────────────────────────────────
    public static function checkStatus(): void {
        $user   = AuthController::requireAuth();
        $userId = $user['id'];
        $db     = getDb();

        // Ensure status is current before checking
        require_once __DIR__ . '/../services/RentalService.php';
        RentalService::updateStatuses($db, $userId);

        $stmt = $db->prepare("SELECT status FROM users WHERE id = ? LIMIT 1");
        $stmt->bind_param('i', $userId);
        $stmt->execute();
        $row = $stmt->get_result()->fetch_assoc();
        $stmt->close();

        if (!$row) sendError('User not found', 404);

        sendSuccess([
            'status' => $row['status'] ?? 'active'
        ]);
    }
}
?>
