<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: POST, OPTIONS");
header("Access-Control-Allow-Headers: Content-Type, Authorization");

if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
    http_response_code(200);
    exit;
}

require_once(__DIR__ . '/../config.php');

$input = json_decode(file_get_contents("php://input"), true);
$slug = $input['slug_tienda'] ?? null;

if (!$slug) {
    echo json_encode(['success' => false, 'message' => 'Falta el slug de la tienda']);
    exit;
}

$stmt = $mysqli->prepare("UPDATE flujos_chatbot SET es_principal = 0 WHERE slug_tienda = ?");
$stmt->bind_param("s", $slug);
$stmt->execute();
$stmt->close();

echo json_encode(['success' => true, 'message' => '🛑 Todos los bots desactivados']);
