<?php
declare(strict_types=1);

require_once __DIR__ . '/AvailabilityEngine.php';
require_once __DIR__ . '/EventBus.php';
require_once __DIR__ . '/SyncQueue.php';
require_once __DIR__ . '/AIInsights.php';

if (!function_exists('hv4_table_exists')) {

    function hv4_table_exists(string $table): bool
    {
        static $cache = [];

        if (isset($cache[$table])) {
            return $cache[$table];
        }

        try {

            $sql = "SHOW TABLES LIKE :table";

            $stmt = db()->prepare($sql);

            $stmt->execute([
                ':table' => $table
            ]);

            $exists = (bool)$stmt->fetchColumn();

            $cache[$table] = $exists;

            return $exists;

        } catch (Throwable $e) {

            $cache[$table] = false;

            return false;
        }
    }
}