<?php
session_start();
require_once 'config.php';

if (!isset($_SESSION['user_id'])) { die("Non connecté"); }
$userId = (int)$_SESSION['user_id'];

echo "<h3>Debug Friends - User #$userId</h3>";
echo "<h4>Toutes mes relations (friends où je suis user_id)</h4>";
$r = $pdo->query("SELECT f.*, u.username as fname FROM friends f JOIN users u ON u.id=f.friend_id WHERE f.user_id=$userId");
foreach($r->fetchAll() as $row) {
    echo "→ ami: {$row['fname']} | status: <strong>{$row['status']}</strong><br>";
}

echo "<h4>Demandes reçues (friend_id=moi)</h4>";
$r2 = $pdo->query("SELECT f.*, u.username as uname FROM friends f JOIN users u ON u.id=f.user_id WHERE f.friend_id=$userId");
foreach($r2->fetchAll() as $row) {
    echo "→ de: {$row['uname']} | status: <strong style='color:".($row['status']==='pending'?'red':'green')."'>{$row['status']}</strong><br>";
}

echo "<h4>ENUM actuel de la colonne status</h4>";
$col = $pdo->query("SHOW COLUMNS FROM friends LIKE 'status'")->fetch();
echo "Type: <strong>{$col['Type']}</strong><br>";
?>
