<?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__ . '/../../core/Validator.php';
require_once __DIR__ . '/../../security/auth_guard_web.php';
$db   = Database::getInstance();
$data = json_decode(file_get_contents('php://input'), true);

Validator::required($data, ['section_id']);

$sectionId = (int)$data['section_id'];

try {

    $stmt = $db->prepare("
        DELETE FROM retail_product_sections
        WHERE id = :id
    ");

    $stmt->execute(['id' => $sectionId]);

    if ($stmt->rowCount() === 0) {
        Response::error('Section not found', 404);
    }

} catch (Throwable $e) {
    Response::error('Failed to delete section', 500);
}

Response::success('Section deleted successfully');
