<?php
declare(strict_types=1);

require_once __DIR__ . '/../../security/auth_guard.php';
require_once __DIR__ . '/../../config/database.php';
require_once __DIR__ . '/../../core/Response.php';
require_once __DIR__ . '/../../security/auth_guard_web.php';
$db = Database::getInstance();
$data = json_decode(file_get_contents('php://input'), true);

if (empty($data['section_id'])) {
    Response::error('section_id required', 422);
}

$stmt = $db->prepare("
    UPDATE retail_product_sections
    SET approval_status = 'Approved',
        status = 'Active',
        approved_by = :by,
        updated_at = NOW()
    WHERE id = :id
");

$stmt->execute([
    'by' => $_SESSION['employee_id'],
    'id' => (int)$data['section_id']
]);

Response::success('Section approved');
