<?php
// Quick API test script
header("Content-Type: application/json");

// Test database connection
const DB_HOST = 'localhost';
const DB_USER = 'root';
const DB_PASS = '';
const DB_NAME = 'smartsave';

try {
    $conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
    
    if ($conn->connect_error) {
        echo json_encode([
            'status' => 'error',
            'message' => 'Database connection failed: ' . $conn->connect_error
        ]);
        exit;
    }
    
    // Get user count
    $result = $conn->query("SELECT COUNT(*) as count FROM users");
    $row = $result->fetch_assoc();
    $userCount = $row['count'];
    
    // Get first user
    $result = $conn->query("SELECT id, full_name, email, phone_number FROM users LIMIT 1");
    $firstUser = $result->fetch_assoc();
    
    echo json_encode([
        'status' => 'success',
        'message' => 'API is working!',
        'database' => 'Connected',
        'total_users' => $userCount,
        'sample_user' => $firstUser,
        'note' => 'Use endpoints like: POST /apis/api.php (with path /register, /login, etc.)'
    ], JSON_PRETTY_PRINT);
    
    $conn->close();
    
} catch (Exception $e) {
    echo json_encode([
        'status' => 'error',
        'message' => $e->getMessage()
    ]);
}
