package cn.iocoder.yudao.module.system.convert.excel;

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;

/**
 * @Author: jinyd
 * @CreateTime: 2025/3/14  14:16
 * @Description:
 * @Version: 4.0
 */


public class SaleFlagConverter implements Converter<Integer> {

    // 定义 Java 类型
    @Override
    public Class<?> supportJavaTypeKey() {
        return Integer.class;
    }

    // 定义 Excel 单元格类型（此处返回 STRING，因为最终显示中文）
    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    // 核心转换逻辑：int -> 中文
    @Override
    public WriteCellData<?> convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
        if (value == null) {
            return new WriteCellData<>("未知");
        }
        switch (value) {
            case 1: return new WriteCellData<>("是");
            case 2: return new WriteCellData<>("否");
            default: return new WriteCellData<>("未知");
        }
    }

}
