<?php
// Include the database connection file
require_once 'connection.php';

// Check if the request method is GET
if ($_SERVER["REQUEST_METHOD"] == "GET") {
    // Initialize the response structure
    $response = array(
        "mutedFriends" => array(),
        "error" => false,
        "message" => ""
    );

    // Get the user_email from the query parameters
    if (isset($_GET['user_email'])) {
        $user_email = $conn->real_escape_string($_GET['user_email']);

        // Attempt select query execution
        $select_sql = "SELECT * FROM `mutefriendstable` WHERE `userEmail` = '$user_email'";
        $result = $conn->query($select_sql);

        // Check if any results were returned
        if ($result->num_rows > 0) {
            // Fetch all results as an associative array
            while ($row = $result->fetch_assoc()) {
                $response['mutedFriends'][] = $row;
            }
            $response['message'] = "Muted friends retrieved successfully.";
        } else {
            $response['message'] = "No muted friends found.";
        }
    } else {
        $response['error'] = true;
        $response['message'] = "User email not provided.";
    }

    // Return the results as JSON
    header('Content-Type: application/json');
    echo json_encode($response);
}

$conn->close();
?>
