<?php
require_once '../includes/config.php';
require_once '../includes/db.php';

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

try {
    if (!isset($_GET['id'])) {
        throw new Exception('ID de producto no proporcionado');
    }

    $db = new Database();
    
    // Verificar si el producto está en uso en la tabla cuotas
    $sql = "SELECT COUNT(*) as count FROM cuotas WHERE producto_id = ?";
    $result = $db->query($sql, [intval($_GET['id'])])->fetch();

    echo json_encode([
        'success' => true,
        'enUso' => $result['count'] > 0
    ]);

} catch (Exception $e) {
    http_response_code(500);
    echo json_encode([
        'success' => false,
        'message' => $e->getMessage()
    ]);
}
