<?php
require_once '../../config/db.php';

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

if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    http_response_code(405);
    echo json_encode(['error' => 'Method not allowed']);
    exit;
}

try {
    $data = json_decode(file_get_contents("php://input"));
    
    if (!isset($data->report_id) || !isset($data->status)) {
        http_response_code(400);
        echo json_encode(['error' => 'Missing report_id or status']);
        exit;
    }

    $rid = (int)$data->report_id;
    $status = $data->status; // 'resolved', 'rejected', 'in_progress'

    $stmt = $pdo->prepare("UPDATE reports SET status = ? WHERE id = ?");
    $stmt->execute([$status, $rid]);
    
    echo json_encode(['status' => 'success', 'message' => 'Report updated']);

} catch (PDOException $e) {
    http_response_code(500);
    echo json_encode(['error' => $e->getMessage()]);
}
?>
