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

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

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