<?php
/**
 * Shared post-condition checks for optional module migrations.
 */
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

class YATOON_Schema_Verifier {
    /**
     * Confirm that every plugin table exists before recording a schema marker.
     *
     * @param string[] $suffixes Table names without the WordPress prefix.
     * @return bool
     */
    public static function tables_exist( array $suffixes ) {
        global $wpdb;
        foreach ( $suffixes as $suffix ) {
            $table = $wpdb->prefix . preg_replace( '/[^a-z0-9_]/i', '', (string) $suffix );
            $found = $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table ) ) );
            if ( $found !== $table ) {
                if ( function_exists( 'yatoon_safe_log' ) ) {
                    yatoon_safe_log( 'Schema migration incomplete; missing table: ' . $table );
                }
                return false;
            }
        }
        return true;
    }
}
