<?php
require_once 'config.php';
require_once 'includes/Database.php';
require_once 'includes/Auth.php';

// Simulate logged in admin user
$_SESSION['user_id'] = 1;
$_SESSION['role'] = 'admin';

$db = new Database();

echo "=== API Test ===\n\n";

// Test 1: List records
echo "1. List test (gelen_arama_suresi):\n";
$_GET['action'] = 'list';
$_GET['criteria_code'] = 'gelen_arama_suresi';

ob_start();
include 'criteria_history_api.php';
$output = ob_get_clean();

echo "Output: $output\n";
$result = json_decode($output, true);
echo "Success: " . ($result['success'] ? 'Yes' : 'No') . "\n";
if (isset($result['data'])) {
    echo "Data count: " . count($result['data']) . "\n";
}
echo "\n";

// Test 2: Add record
echo "2. Add test:\n";
$_GET = [];
$_POST['action'] = 'add';
$_POST['criteria_code'] = 'giden_arama_suresi';
$_POST['point_value'] = 0.25;
$_POST['start_date'] = '2025-05-01';
$_POST['end_date'] = '2025-06-30';
$_POST['notes'] = 'API test kaydı';

ob_start();
include 'criteria_history_api.php';
$output = ob_get_clean();

echo "Output: $output\n";
$result = json_decode($output, true);
echo "Success: " . ($result['success'] ? 'Yes' : 'No') . "\n";
echo "Message: " . ($result['message'] ?? 'N/A') . "\n";
