<?php

/**
 * Module availability helper functions.
 *
 * @package ArraySubs\Functions
 */

defined('ABSPATH') || exit;

/**
 * Check whether a booted module/provider class contains a given class name fragment.
 *
 * @param string $moduleClassNamePartial Partial class name to match.
 * @return int Returns -1 for ProFeatures classes, 0 if unavailable, 1 if available.
 */
function arraysubs_has_module(string $moduleClassNamePartial): int
{
    if (str_contains($moduleClassNamePartial, 'ProFeatures')) {
        return -1;
    }

    $liveBootClasses = \ArraySubs\Supports\Config::get('live_boot_classes');

    if (!is_array($liveBootClasses) || empty($liveBootClasses)) {
        return 0;
    }

    foreach ($liveBootClasses as $class) {
        if (is_string($class) && str_contains($class, $moduleClassNamePartial)) {
            return 1;
        }
    }

    return 0;
}
