<?php
require_once __DIR__ . '/../includes/config.php';
if (file_exists(__DIR__ . '/../includes/auth.php')) {
    require_once __DIR__ . '/../includes/auth.php';
}
require_once __DIR__ . '/functions.php';

admin_require_post_action('customer_verification', admin_url('customers/list.php'));

$id = (int)($_POST['id'] ?? 0);
$value = (int)($_POST['value'] ?? -1);
if ($id <= 0 || ($value !== 0 && $value !== 1)) {
    cust_redirect(admin_url('customers/list.php?msg=') . urlencode('البيانات غير صحيحة'));
}

$result = cust_set_customer_verification($id, $value);
$back = (string)($_POST['back'] ?? admin_url('customers/list.php'));
if (!str_starts_with($back, '/app/admin/customers/')) {
    $back = admin_url('customers/list.php');
}
admin_log_activity('customer.set_verification', 'تغيير حالة OTP للزبون', 'تم تنفيذ تغيير إداري على الزبون.', 'customer', $id, ['value' => $value], true);
$separator = (strpos($back, '?') !== false) ? '&' : '?';
cust_redirect($back . $separator . 'msg=' . urlencode($result['message']));
