<?php

require_once __DIR__ . '/../../config/database.php';
require_once __DIR__ . '/../../config/helpers.php';
require_once __DIR__ . '/../../middleware/auth.php';

if (getMethod() !== 'POST') {
    jsonResponse(false, 'Method not allowed', null, 405);
}

global $pdo;
$user = requireAuth();

$stmt = $pdo->prepare(
    'UPDATE user_sessions
     SET is_revoked = 1, updated_at = NOW()
     WHERE user_id = :user_id AND id <> :current_session_id AND is_revoked = 0'
);
$stmt->execute([
    'user_id' => $user['id'],
    'current_session_id' => $user['session_id'],
]);

jsonResponse(true, 'Other sessions revoked successfully', [
    'revoked_count' => $stmt->rowCount(),
]);
