package org.xyzh.common.utils.excel;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @description Excel读取结果
 * @filename ExcelReadResult.java
 * @author yslg
 * @copyright xyzh
 * @since 2025-10-16
 */
public class ExcelReadResult<T> {
    
    /**
     * @description 是否成功
     */
    private boolean success;
    
    /**
     * @description 成功读取的数据列表
     */
    private List<T> dataList;
    
    /**
     * @description 失败的行数据（行号 -> 错误信息）
     */
    private Map<Integer, String> errorRowsMap;
    
    /**
     * @description 总行数（不包括表头）
     */
    private int totalRows;
    
    /**
     * @description 成功行数
     */
    private int successRows;
    
    /**
     * @description 失败行数
     */
    private int errorRowsCount;
    
    /**
     * @description 错误信息
     */
    private String errorMessage;
    
    public ExcelReadResult() {
        this.success = true;
        this.dataList = new ArrayList<>();
        this.errorRowsMap = new HashMap<>();
        this.totalRows = 0;
        this.successRows = 0;
        this.errorRowsCount = 0;
    }
    
    public boolean isSuccess() {
        return success;
    }
    
    public void setSuccess(boolean success) {
        this.success = success;
    }
    
    public List<T> getDataList() {
        return dataList;
    }
    
    public void setDataList(List<T> dataList) {
        this.dataList = dataList;
    }
    
    public Map<Integer, String> getErrorRows() {
        return errorRowsMap;
    }
    
    public void setErrorRows(Map<Integer, String> errorRowsMap) {
        this.errorRowsMap = errorRowsMap;
    }
    
    public int getTotalRows() {
        return totalRows;
    }
    
    public void setTotalRows(int totalRows) {
        this.totalRows = totalRows;
    }
    
    public int getSuccessRows() {
        return successRows;
    }
    
    public void setSuccessRows(int successRows) {
        this.successRows = successRows;
    }
    
    public int getErrorRowsCount() {
        return errorRowsCount;
    }
    
    public void setErrorRowsCount(int errorRowsCount) {
        this.errorRowsCount = errorRowsCount;
    }
    
    public String getErrorMessage() {
        return errorMessage;
    }
    
    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }
    
    public void addData(T data) {
        this.dataList.add(data);
        this.successRows++;
    }
    
    public void addError(int rowNum, String error) {
        this.errorRowsMap.put(rowNum, error);
        this.errorRowsCount++;
    }
    
    public boolean hasErrors() {
        return this.errorRowsCount > 0;
    }
    
    @Override
    public String toString() {
        return "ExcelReadResult{" +
                "success=" + success +
                ", totalRows=" + totalRows +
                ", successRows=" + successRows +
                ", errorRows=" + errorRowsCount +
                ", errorMessage='" + errorMessage + '\'' +
                '}';
    }
}

