package org.dromara.zhishu.converter;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;

public class QualityConverter implements Converter<String> {  // 改为 String

    @Override
    public Class<String> supportJavaTypeKey() {  // 改为 String.class
        return String.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    @Override
    public WriteCellData<?> convertToExcelData(String codeStr, ExcelContentProperty contentProperty,
                                               GlobalConfiguration globalConfiguration) throws Exception {
        if (codeStr == null || codeStr.trim().isEmpty()) {
            return new WriteCellData<>("");
        }

        try {
            // 将字符串转为整数进行判断
            int code = Integer.parseInt(codeStr);
            String qualityDesc;
            switch (code) {
                case 100:
                    qualityDesc = "全新";
                    break;
                case 95:
                    qualityDesc = "九五品";
                    break;
                case 90:
                    qualityDesc = "九品";
                    break;
                case 85:
                    qualityDesc = "八五品";
                    break;
                case 80:
                    qualityDesc = "八品";
                    break;
                case 75:
                    qualityDesc = "七五品";
                    break;
                case 70:
                    qualityDesc = "七品";
                    break;
                case 65:
                    qualityDesc = "六五品";
                    break;
                case 60:
                    qualityDesc = "六品";
                    break;
                default:
                    qualityDesc = codeStr;
                    break;
            }
            return new WriteCellData<>(qualityDesc);
        } catch (NumberFormatException e) {
            // 如果不是数字，直接返回原值
            return new WriteCellData<>(codeStr);
        }
    }
}