<?php
session_start();
if (!isset($_SESSION['user_id'])) {
    echo json_encode(['status' => 'error', 'message' => 'Usuário não está logado']);
    exit();
}

$host = 'localhost';
$db = 'digupdog_FEED';
$user = 'digupdog_FEEDadmin';
$pass = 'Raimundinho1';
$charset = 'utf8mb4';

$conn = new mysqli($host, $user, $pass, $db);
if ($conn->connect_error) {
    die("Erro na conexão com o banco de dados: " . $conn->connect_error);
}
$conn->set_charset("utf8mb4");

$userId = $_SESSION['user_id'];
$follows = $_POST['follows']; // Array de follow_type e follow_value

$response = [];

foreach ($follows as $follow) {
    $followType = $follow['follow_type'];
    $followValue = $follow['follow_value'];

    $stmt = $conn->prepare("SELECT * FROM follows WHERE user_id = ? AND follow_type = ? AND follow_value = ?");
    $stmt->bind_param("iss", $userId, $followType, $followValue);
    $stmt->execute();
    $result = $stmt->get_result();

    // Retornar o status para cada follow
    if ($result->num_rows > 0) {
        $response[$followType . $followValue] = 'following';
    } else {
        $response[$followType . $followValue] = 'not_following';
    }
}

echo json_encode($response);
?>
