<?php

require '../config/database.php';
session_start();

header('Content-Type: application/json');

$concernId = intval($_GET['concern_id']);

$stmt = $pdo->prepare("
SELECT
    e.id,
    e.file_path,
    e.uploaded_at,

    u.first_name,
    u.last_name

FROM safety_concern_evidence e

LEFT JOIN users u
ON e.uploaded_by = u.id

WHERE concern_id = ?

ORDER BY uploaded_at DESC
");

$stmt->execute([$concernId]);

$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);

echo json_encode([
    "status" => "success",
    "data" => $rows
]);