package nckd.jxccl.base.common.utils;

import kd.bos.entity.ISVInfo;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.servicehelper.ISVServiceHelper;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 模型工具类
 * 用于校验属性名称是否包含特殊字符或是否扩展字段
 * @from: kd.hr.homs.business.utils.PatternUtil
 * @author: jtd
 * @date: 2025/12/24 19:45
 */
public class PatternUtil {
    private static final Log logger = LogFactory.getLog(PatternUtil.class);
    private static final char[] SPECIAL_SEPARATORS = new char[]{'!', '_', '\\'};
    private static final Pattern SPECIAL_SEPARATORS_REGEX;
    public static final String ISV_ID;
    public static final String ISV_NAME;

    static {
        StringBuilder stringBuffer = new StringBuilder();

        for(int i = 0; i < SPECIAL_SEPARATORS.length; ++i) {
            stringBuffer.append("\\").append(SPECIAL_SEPARATORS[i]).append("+");
            if (i < SPECIAL_SEPARATORS.length - 1) {
                stringBuffer.append("|");
            }
        }

        SPECIAL_SEPARATORS_REGEX = Pattern.compile(stringBuffer.toString());
        ISVInfo isvInfo = ISVServiceHelper.getISVInfo();
        ISV_ID = isvInfo.getId();
        ISV_NAME = isvInfo.getName();
        logger.info("do isExProperty,the isv is {} {}", ISV_ID, ISV_NAME);
    }

    public static boolean valideName(String orgName) {
        Matcher matcher = SPECIAL_SEPARATORS_REGEX.matcher(orgName);
        return matcher.find();
    }

    public static boolean isExProperty(String property) {
        if (property == null) {
            return false;
        } else {
            return property.endsWith("_ext") || property.contains(ISV_ID + "_") || property.contains(ISV_NAME + "_");
        }
    }
}
