<?php
include '../inc/db.php';

header('Content-Type: application/json');

if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    echo json_encode(['status' => 'error', 'message' => 'Invalid request']);
    exit;
}

$id = intval($_POST['id'] ?? 0);

if ($id <= 0) {
    echo json_encode(['status' => 'error', 'message' => 'Invalid ID']);
    exit;
}

/* ✅ CHECK EXISTS */
$check = mysqli_query($conn, "SELECT id FROM variant_groups WHERE id=$id");

if (mysqli_num_rows($check) == 0) {
    echo json_encode(['status' => 'error', 'message' => 'Variant not found']);
    exit;
}

/* ✅ DELETE */
$del = mysqli_query($conn, "DELETE FROM variant_groups WHERE id=$id");

if ($del) {
    echo json_encode(['status' => 'success', 'message' => 'Variant deleted']);
} else {
    echo json_encode(['status' => 'error', 'message' => 'Delete failed']);
}
