<?php
/**
 * Auth Logout Endpoint
 */

use App\Core\Database;
use App\Middleware\AuthMiddleware;

// 1. Check Authentication
$decoded = AuthMiddleware::check();
$userId = $decoded['user_id'];

// 2. Invalidate Refresh Token
$db = Database::getInstance();
$stmt = $db->prepare("UPDATE users SET refresh_token_hash = NULL WHERE id = ?");
$stmt->execute([$userId]);

json_success(null, 'تم تسجيل الخروج بنجاح');
