<?php
require_once 'config.php';
require_once 'includes/Database.php';
require_once 'includes/Auth.php';

Auth::requireLogin();

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

$db = new Database();

try {
    $id = $_GET['id'] ?? null;
    
    if (!$id) {
        throw new Exception('ID parametresi eksik');
    }
    
    // Eğitim detayını çek
    $training = $db->fetchOne("
        SELECT 
            id,
            company_id,
            company_name,
            sales_source,
            support_representative,
            training_completion_date,
            sales_type,
            package_type,
            created_at
        FROM training_completion
        WHERE id = ?
    ", [$id]);
    
    if (!$training) {
        throw new Exception('Eğitim kaydı bulunamadı');
    }
    
    echo json_encode([
        'success' => true,
        'training' => $training
    ]);
    
} catch (Exception $e) {
    echo json_encode([
        'success' => false,
        'error' => $e->getMessage()
    ]);
}
