<?php
require_once __DIR__ . "/../auth/require-auth.php";
require_once __DIR__ . "/../services/db.php";

$taskId = $_GET["task"];

$sql = "SELECT * FROM attachments
        WHERE task_id = ?
        ORDER BY uploaded_at DESC";
$stmt = sqlsrv_query($conn, $sql, [$taskId]);

$items = [];
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
    $items[] = $row;
}

echo json_encode($items);
