<?php
require 'db.php';
require 'functions.php';

$mobileoremail = cleanInput($_POST['mobileoremail'] ?? '');

if ($mobileoremail === '') {
    jsonOut(false, 'Please provide your registered mobile number or email');
}

try {
    $stmt = $pdo->prepare("INSERT INTO deleteaccountrequest (mobileoremail, status) VALUES (?, 'pending')");
    $stmt->execute([$mobileoremail]);

    logActivity($pdo, 'deleteaccountrequest', (int)$pdo->lastInsertId(), 'create', 'public', null, 'Delete request via web for ' . $mobileoremail);

    jsonOut(true, 'Your request has been received. Our team will process it shortly.');
} catch (Exception $e) {
    logDebug('[ajax_deleteaccount] ' . $e->getMessage());
    jsonOut(false, 'Something went wrong. Please try again.');
}
