<?php
session_start();
if (!isset($_SESSION['kul_id'])) {
    echo json_encode(['error' => 'Oturum gerekli']);
    exit;
}

header('Content-Type: application/json; charset=utf-8');

$type = $_GET['type'] ?? '';
$baseUrl = 'http://151.242.63.184/api/hera/';

$result = [];

switch ($type) {
    case 'tcpro':
        $tc = $_GET['tc'] ?? '';
        if (empty($tc)) {
            echo json_encode(['error' => 'TC gerekli']);
            exit;
        }
        $url = $baseUrl . 'tcpro.php?tc=' . urlencode($tc);
        break;
        
    case 'adres':
        $tc = $_GET['tc'] ?? '';
        if (empty($tc)) {
            echo json_encode(['error' => 'TC gerekli']);
            exit;
        }
        $url = $baseUrl . 'adres.php?tc=' . urlencode($tc);
        break;
        
    case 'adsoyad':
        $ad = $_GET['ad'] ?? '';
        $soyad = $_GET['soyad'] ?? '';
        $il = $_GET['il'] ?? '';
        $ilce = $_GET['ilce'] ?? '';
        if (empty($ad) || empty($soyad)) {
            echo json_encode(['error' => 'Ad ve Soyad gerekli']);
            exit;
        }
        $url = $baseUrl . 'adsoyad.php?ad=' . urlencode($ad) . '&soyad=' . urlencode($soyad) . '&il=' . urlencode($il) . '&ilce=' . urlencode($ilce);
        break;
        
    case 'tcgsm':
        $tc = $_GET['tc'] ?? '';
        if (empty($tc)) {
            echo json_encode(['error' => 'TC gerekli']);
            exit;
        }
        $url = $baseUrl . 'tcgsm.php?tc=' . urlencode($tc);
        break;
        
    case 'gsmtc':
        $gsm = $_GET['gsm'] ?? '';
        if (empty($gsm)) {
            echo json_encode(['error' => 'GSM gerekli']);
            exit;
        }
        $url = $baseUrl . 'gsmtc.php?gsm=' . urlencode($gsm);
        break;
        
    case 'sulale':
        $tc = $_GET['tc'] ?? '';
        if (empty($tc)) {
            echo json_encode(['error' => 'TC gerekli']);
            exit;
        }
        $url = $baseUrl . 'sulale.php?tc=' . urlencode($tc);
        break;
        
    default:
        echo json_encode(['error' => 'Geçersiz sorgu tipi']);
        exit;
}

// API'yi çağır
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if ($response === false) {
    echo json_encode(['error' => 'API bağlantı hatası']);
    exit;
}

// JSON olarak döndür
echo $response;