<?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();
$data = json_decode(file_get_contents('php://input'), true);

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

$variantId = (int)$data['variant_id'];

/**
 * Validate variant
 */
$stmt = $db->prepare("
    SELECT id FROM retail_product_variants
    WHERE id = :id
");
$stmt->execute(['id' => $variantId]);

if (!$stmt->fetch()) {
    Response::error('Variant not found', 404);
}

/**
 * Soft delete (deactivate)
 */
$stmt = $db->prepare("
    UPDATE retail_product_variants
    SET
        status = 'InActive',
        updated_at = NOW()
    WHERE id = :id
");

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

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