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

$user_id = $_SESSION['user_id'];

// Conexão com o banco de dados
$host = 'localhost';
$db = 'digupdog_FEED';
$user = 'digupdog_FEEDadmin';
$pass = 'Raimundinho1';
$conn = new mysqli($host, $user, $pass, $db);
if ($conn->connect_error) {
    die("Erro na conexão com o banco de dados: " . $conn->connect_error);
}

// Consulta para obter os IDs dos feeds salvos
$query = "SELECT feed_id FROM favorites WHERE user_id = ?";
$stmt = $conn->prepare($query);
$stmt->bind_param("i", $user_id);
$stmt->execute();
$result = $stmt->get_result();

$savedFeeds = [];
while ($row = $result->fetch_assoc()) {
    $savedFeeds[] = $row['feed_id'];  // Obtemos apenas o ID do feed salvo
}

echo json_encode(['status' => 'success', 'savedFeeds' => $savedFeeds]);

$stmt->close();
$conn->close();
?>
