<?php
include "../db_connect.php";

$user_id = $_POST['user_id']; // লগইন করা ইউজারের আইডি


$con = dbConnect();

// যাদের সে ফলো করেছে
$following_query = "
    SELECT u.id, u.name, u.image
    FROM followers f
    JOIN singup_table u ON f.following_id = u.id
    WHERE f.follower_id = ?
";

// যাদের তাকে ফলো করছে
$followers_query = "
    SELECT u.id, u.name, u.image
    FROM followers f
    JOIN singup_table u ON f.follower_id = u.id
    WHERE f.following_id = ?
";

$response = [
    "following" => [],
    "followers" => [],
    "following_count" => 0,
    "followers_count" => 0
];

// Followers list
$stmt = $con->prepare($followers_query);
$stmt->bind_param("i", $user_id);
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
    $response["followers"][] = $row;
}
$response["followers_count"] = count($response["followers"]);


// Followers list
$stmt = $con->prepare($followers_query);
$stmt->bind_param("i", $user_id);
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
    $response["followers"][] = $row;
}
$response["followers_count"] = count($response["followers"]);

echo json_encode($response);
?>
