<?php
// delete_user.php - Delete User
// File location: /bidwheels.net/admin/delete_user.php

require_once '../includes/auth.php';
require_once '../includes/functions.php';

requireAdmin();

$user_id = isset($_GET['id']) ? (int)$_GET['id'] : 0;

if ($user_id <= 0) {
    setError('Invalid user ID.');
    redirect('/admin/users.php');
}

$user = fetchOne("SELECT is_dummy, role FROM users WHERE id = $user_id");

if (!$user) {
    setError('User not found.');
    redirect('/admin/users.php');
}

if ($user['role'] == 'admin') {
    setError('Cannot delete admin users.');
    redirect('/admin/users.php');
}

if ($user['is_dummy'] == 0) {
    setError('Cannot delete real users. Only dummy users can be deleted.');
    redirect('/admin/users.php');
}

// Delete user (cascades to bids, comments, payments)
delete('users', "id = $user_id");

setSuccess('Dummy user deleted successfully.');
redirect('/admin/users.php');
?>