package ${domain}.frame.excel.handler;

import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.write.handler.CellWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row;
import ${domain}.frame.excel.WHead;

import java.util.List;
import java.util.Map;

public class WCellWriteHandler implements CellWriteHandler {
    private CellStyle[] styles;

    private Map<Integer, List<String>> errMap;

    public WCellWriteHandler(List<WHead> wHeads, CellStyle[] styles, Map<Integer, List<String>> errMap) {
        this.styles = styles;
        this.errMap = errMap;
    }


    @Override
    public void beforeCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row, Head head, Integer integer, Integer integer1, Boolean isHead) {

    }

    @Override
    public void afterCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Cell cell, Head head, Integer integer, Boolean isHead) {

    }

    @Override
    public void afterCellDataConverted(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, CellData cellData, Cell cell, Head head, Integer integer, Boolean isHead) {

    }

    @Override
    public void afterCellDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, List<CellData> list, Cell cell, Head head, Integer rowIndex, Boolean isHead) {
        if (isHead) {
            cell.setCellStyle(styles[0]);
        } else if (errMap.get(rowIndex) != null) {
            cell.setCellStyle(styles[1]);
        }
    }
}
