<?php
/**
 * 芋头CMS
 * ============================================================================
 * 版权所有 2016-2028 沅陵县乌托邦网络服务有限公司，并保留所有权利。
 * 网站地址: http://www.yutoucms.cn
 * ----------------------------------------------------------------------------
 * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
 * ============================================================================
 * Author: 芋头 <mxgsf@qq.com>
 * Date: 2026-6-10
 */

namespace Core\Lib;

require_once __DIR__ . '/license.php';

class LicenseGuard
{
    public static function getLicense($license = null)
    {
        if ($license instanceof License) {
            return $license;
        }

        return new License();
    }

    public static function hasFeature($feature, $license = null)
    {
        $license = self::getLicense($license);
        return $license->hasFeature($feature);
    }

    public static function canUseOrder($license = null)
    {
        $license = self::getLicense($license);
        return $license->canUseOrder();
    }

    public static function canUsePayment($license = null)
    {
        $license = self::getLicense($license);
        return $license->canUsePayment();
    }

    public static function canUseBuilder($license = null)
    {
        $license = self::getLicense($license);
        return $license->canUseBuilder();
    }

    public static function getDeniedMessage($feature, $license = null, $fallback = '当前授权不支持该功能')
    {
        $license = self::getLicense($license);
        if (method_exists($license, 'disabledMessage')) {
            return $license->disabledMessage($feature);
        }

        return $fallback;
    }
}
