<?php
header('Content-Type: application/json');
include "../db.php";

error_reporting(E_ERROR | E_PARSE);
ini_set('display_errors', 0);

$result = $conn->query("SELECT * FROM job_listing ORDER BY id DESC");

$jobs = [];
while ($row = $result->fetch_assoc()) {
    $row['requirements'] = json_decode($row['requirements'] ?? '[]');
    $row['postedDaysAgo'] = (int)$row['postedDaysAgo']; // dynamically calculated
    $jobs[] = $row;
}

echo json_encode($jobs);
$conn->close();
exit;
?>
