<?php

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

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

$data = json_decode(file_get_contents("php://input"), true);

if (!isset($data['concern_id'], $data['status'])) {
    echo json_encode([
        "status" => "error",
        "message" => "Missing parameters"
    ]);
    exit;
}

$id = intval($data['concern_id']);
$status = $data['status'];

$allowed = [
    "OPEN",
    "IN_PROGRESS",
    "OVERDUE",
    "RESOLVED",
    "CLOSED"
];

if (!in_array($status, $allowed)) {
    echo json_encode([
        "status" => "error",
        "message" => "Invalid status"
    ]);
    exit;
}

$stmt = $pdo->prepare("
UPDATE safety_concerns
SET status = ?
WHERE id = ?
");

$stmt->execute([$status, $id]);

echo json_encode([
    "status" => "success"
]);