<?php
require_once __DIR__.'/../../config.php';
require_once __DIR__ . '/../../engine/Kernel.php';
Kernel::handle(['auth' => false, 'public' => true]);
require_once __DIR__.'/../../engine/Logger.php';
require_once __DIR__.'/../../engine/AgentEngine.php';
$lat = (float)($_GET['lat']??0);
$lng = (float)($_GET['lng']??0);
if($lat&&$lng){
  $agents = AgentEngine::getNearbyAgents($lat,$lng);
} else {
  $city = $_GET['city']??'';
  $st = db()->prepare("SELECT * FROM sdpay_agents WHERE status='active'".($city?" AND city=?":'')." ORDER BY business_name LIMIT 30");
  $st->execute($city?[$city]:[]);
  $agents = $st->fetchAll();
}
echo json_encode(['ok'=>true,'data'=>$agents], JSON_UNESCAPED_UNICODE);
