<?php
/**
 * GET /api/public/pricing.php
 * الأسعار العامة — لا يحتاج auth
 * Cache: 5 min | Returns: SDG prices for plans, docs, images, videos
 */
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 '../../engine/PricingEngine.php';

header('Access-Control-Allow-Origin: *');
header('Cache-Control: public, max-age=300');

try {
    $data = PricingEngine::getAll();
    // Enrich with images + videos for the universal pricing-loader.js
    $data['images'] = PricingEngine::getImagePrices();
    $data['videos'] = PricingEngine::getVideoPrices();
    echo json_encode($data, JSON_UNESCAPED_UNICODE);
} catch (Throwable $e) {
    http_response_code(500);
    echo json_encode(['error' => 'server_error', 'message' => 'خطأ مؤقت — حاول مرة أخرى'], JSON_UNESCAPED_UNICODE);
}
