<?php
declare(strict_types=1);

require_once __DIR__ . '/../../security/auth_guard.php';
require_once __DIR__ . '/../../config/database.php';
require_once __DIR__ . '/../../core/Response.php';

$db = Database::getInstance();

$productId = (int) ($_GET['product_id'] ?? 0);
if ($productId <= 0) {
    Response::error('Product ID required', 422);
}

$stmt = $db->prepare("
    SELECT *
    FROM retail_product_sections
    WHERE product_id = :product_id
    ORDER BY priority ASC, id DESC
");

$stmt->execute(['product_id' => $productId]);

Response::success('Sections fetched successfully', [
    'sections' => $stmt->fetchAll()
]);
