<?php
require_once '../app/Core/init.php';
Auth::requireAdmin();

if (!isset($_GET['id'])) {
    echo json_encode(['success' => false]);
    exit;
}

$category_model = new Category();
$category = $category_model->find((int)$_GET['id']);

if ($category) {
    echo json_encode([
        'success' => true,
        'category' => [
            'id' => $category['id'],
            'name' => $category['name'],
            'description' => $category['description'],
            'icon' => $category['icon'],
            'parent_id' => $category['parent_id'],
            'status' => $category['status'],
            'display_order' => $category['display_order'] ?? 0,
            'commission_percentage' => $category['commission_percentage'] ?? 10.00,
            'level' => $category['level'] ?? 'medium'
        ]
    ]);
} else {
    echo json_encode(['success' => false]);
}