<?php
declare(strict_types=1);
require_once __DIR__ . '/../../security/auth_guard_web.php';
//require_once __DIR__ . '/../../security/auth_guard.php';
require_once __DIR__ . '/../../config/database.php';
require_once __DIR__ . '/../../core/Response.php';

$data = json_decode(file_get_contents('php://input'), true);

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

$allowed = ['Active','InActive','Draft'];

if (!in_array($data['status'], $allowed, true)) {
    Response::error('Invalid status', 422);
}

$stmt = $db->prepare("
    UPDATE retail_product_sections
    SET status = :status, updated_at = NOW()
    WHERE id = :id
");

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

Response::success('Status updated');
