<?php
require_once __DIR__ . '/../../config/secure_bootstrap.php';
header('Content-Type: application/json; charset=utf-8');

try {
    $id = intval($_GET['id'] ?? 0);
    if ($id <= 0) {
        throw new Exception('ID tidak valid');
    }

    $stmt = $pdo->prepare("SELECT * FROM audit_findings WHERE id = ?");
    $stmt->execute([$id]);
    $data = $stmt->fetch(PDO::FETCH_ASSOC);

    if (!$data) {
        echo json_encode(['success' => false, 'message' => 'Data tidak ditemukan']);
    } else {
        echo json_encode(['success' => true, 'data' => $data]);
    }
} catch (Throwable $e) {
    echo json_encode(['success' => false, 'message' => $e->getMessage()]);
}
