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.common.houqin.constant.LeConstants;

import java.util.Objects;

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

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

   @Override
   public Integer convertToJavaData(ReadCellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
      return NumberUtil.parseInt(cellData.getStringValue());
   }

   @Override
   public WriteCellData convertToExcelData(Integer s, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
      if (Objects.equals(LeConstants.COMMON_YES, s)) {
         return new WriteCellData("是");
      } else {
         return Objects.equals(LeConstants.COMMON_NO, s) ? new WriteCellData("否") : new WriteCellData("");
      }
   }
}
