package com.muchinfo.mtp3pojos.exportconverter;

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;

public class AccountStatusConverter implements Converter<Integer> {
    private static final String NO_ACTIVATE = "待激活";
    private static final String NO_REVIEW = "待审核";
    private static final String PENDING_REVIEW = "待复核";
    private static final String NORMAL = "正常";
    private static final String REVIEW_REJECT = "审核拒绝";
    private static final String DEACTIVATE = "停用(注销)";
    private static final String DELETE = "注销(删除)";

    @Override
    public Class<?> supportJavaTypeKey() {
        // 实体类中对象属性类型
        return Integer.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        // Excel中对应的CellData属性类型
        return CellDataTypeEnum.STRING;
    }

    @Override
    public Integer convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        // 从Cell中读取数据
        String gender = cellData.getStringValue();
        // 判断Excel中的值，将其转换为预期的数值
        if (NO_ACTIVATE.equals(gender)) {
            return 1;
        } else if (NO_REVIEW.equals(gender)) {
            return 2;
        } else if (PENDING_REVIEW.equals(gender)) {
            return 3;
        } else if (NORMAL.equals(gender)) {
            return 4;
        } else if (REVIEW_REJECT.equals(gender)) {
            return 5;
        } else if (DEACTIVATE.equals(gender)) {
            return 6;
        } else if (DELETE.equals(gender)) {
            return 7;
        }
        return null;
    }

    @Override
    public WriteCellData<?> convertToExcelData(Integer integer, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        // 判断实体类中获取的值，转换为Excel预期的值，并封装为CellData对象
        if (integer == null) {
            return new WriteCellData<>("");
        } else if (integer == 1) {
            return new WriteCellData<>(NO_ACTIVATE);
        } else if (integer == 2) {
            return new WriteCellData<>(NO_REVIEW);
        } else if (integer == 3) {
            return new WriteCellData<>(PENDING_REVIEW);
        } else if (integer == 4) {
            return new WriteCellData<>(NORMAL);
        } else if (integer == 5) {
            return new WriteCellData<>(REVIEW_REJECT);
        } else if (integer == 6) {
            return new WriteCellData<>(DEACTIVATE);
        } else if (integer == 7) {
            return new WriteCellData<>(DELETE);
        }
        return new WriteCellData<>("");
    }
}
