<?php
include "config.php";

$allowed_types = ['Unable to Withdraw', 'Severe Slippage', 'Scam', 'Others'];
$type = $_GET['type'] ?? 'Others';

// Validate the type against allowed types
if (!in_array($type, $allowed_types)) {
    $type = 'Others';
}

// Prepare the LIKE query with wildcards
$stmt = $dbh->prepare("SELECT * FROM protection_reports WHERE type LIKE ? ORDER BY report_date DESC");

// Add wildcards for partial matching
$like_type = "%{$type}%";

$stmt->execute([$like_type]);
$reports = $stmt->fetchAll();

echo json_encode($reports);
