<?php
session_start();
include "config.php";

if (!isset($_SESSION['user'])) {
    echo "error|unauthorized";
    exit;
}

if (!isset($_POST['id'], $_POST['kycid'])) {
    echo "error|missing";
    exit;
}

$id = (int) $_POST['id'];
$kycid = (int) $_POST['kycid'];

// 🔒 Ensure bank account belongs to this KYC
$query = "DELETE FROM bank_accounts WHERE id = $id AND kyc_id = $kycid";

if (mysqli_query($con, $query)) {
    if (mysqli_affected_rows($con) > 0) {
        echo "success";
    } else {
        echo "error|not_found";
    }
} else {
    echo "error|" . mysqli_error($con);
}