package com.bonus.canteen.core.common.utils;

import cn.hutool.core.util.NumberUtil;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.bonus.canteen.core.common.constant.ConsumModeEnum;

public class CustomConsumModeConverter implements Converter<Integer> {
   public Class supportJavaTypeKey() {
      return Integer.class;
   }

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

   public Integer convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) {
      return NumberUtil.parseInt(cellData.getStringValue());
   }

   public WriteCellData<Integer> convertToExcelData(Integer s, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
      return new WriteCellData(ConsumModeEnum.getDesc(s));
   }
}
