<?php
require_once __DIR__ . '/../../config/database.php';

$stmt = $pdo->prepare("
    SELECT p.limite_empresas
    FROM usuarios u
    JOIN planos p ON p.id = u.plano_id
    WHERE u.id = ?
");
$stmt->execute([$_SESSION['user_id']]);
$plano = $stmt->fetch();

$stmt = $pdo->prepare("
    SELECT COUNT(*) FROM empresas WHERE usuario_id = ?
");
$stmt->execute([$_SESSION['user_id']]);
$total = $stmt->fetchColumn();

if ($total >= $plano['limite_empresas']) {
    die('❌ Limite do plano atingido. Faça upgrade.');
}
