package com.lideeyunji.core.framework.config.excel.check;

import com.lideeyunji.core.framework.config.excel.check.strategy.ExcelDataLengthStrategy;
import com.lideeyunji.core.framework.config.excel.check.strategy.ExcelDataTypeStrategy;
import com.lideeyunji.tool.framework.yunji.tool.spring.SpringUtils;

public enum ExcelCheckEnums {

    DATA_TYPE("数据类型校验","DATA_TYPE", ExcelDataTypeStrategy.class),
    DATA_LENGTH("数据长度校验","DATA_LENGTH", ExcelDataLengthStrategy.class),

    ;

    private final String name;
    private final String code;
    private final Class<? extends IExcelCheckStrategy> strategyClass;


    ExcelCheckEnums(String name, String code, Class<? extends IExcelCheckStrategy> strategyClass) {
        this.name = name;
        this.code = code;
        this.strategyClass = strategyClass;
    }

    public String getName() {
        return name;
    }

    public String getCode() {
        return code;
    }

    public Class<? extends IExcelCheckStrategy> getStrategyClass() {
        return strategyClass;
    }

    // 获取实际的策略实例（通过Spring工具类）
    public IExcelCheckStrategy getStrategy() {
        String beanName = firstCharToLowerCase(strategyClass.getSimpleName());
        return SpringUtils.getBean(beanName);
    }


    public static String firstCharToLowerCase(String str) {
        if (str == null || str.isEmpty()) {
            return str;
        }
        char[] chars = str.toCharArray();
        chars[0] = Character.toLowerCase(chars[0]);
        return new String(chars);
    }
}
