<?php
header('Content-Type: application/json');

require_once __DIR__ . '/config.php';
require_once __DIR__ . '/functions.php';

$res = nexusGetProviderList();

if (!isset($res['status']) || $res['status'] != 1) {
  echo json_encode([
    'success' => false,
    'msg' => $res['msg'] ?? 'Provider API gagal',
    'raw' => $res
  ]);
  exit;
}

$providers = [];

if (!empty($res['providers'])) {
  foreach ($res['providers'] as $p) {
    // ambil hanya provider aktif
    if ((int)$p['status'] === 1) {
      $providers[] = [
        'code' => strtolower($p['code']),
        'name' => strtoupper($p['name'])
      ];
    }
  }
}

echo json_encode([
  'success' => true,
  'providers' => $providers
]);