<?php
/**
 * GET /api/bills/providers.php
 * WAVE E — Full Kernel Replace
 */
require_once __DIR__ . '/../../config.php';
require_once __DIR__ . '/../../engine/Kernel.php';

$ctx = Kernel::handle(['auth' => true]);

try {
    $providers = db()->query(
        "SELECT id, name_ar, name_en, category, logo_url, account_format
         FROM sdpay_bill_providers WHERE is_active=1 ORDER BY category, name_ar"
    )->fetchAll(PDO::FETCH_ASSOC);
    Kernel::respond(['providers' => $providers, 'count' => count($providers)]);
} catch (Throwable $e) {
    Logger::error('bill_providers_failed', ['error' => $e->getMessage()]);
    Kernel::fail('fetch_failed', 'تعذّر تحميل موفري الفواتير', 500);
}
