package cn.iocoder.yudao.module.member.convert.excel;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.converters.ReadConverterContext;
import com.alibaba.excel.converters.WriteConverterContext;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.data.WriteCellData;
import org.springframework.stereotype.Component;

/**
 * @author zt
 * @description <description class purpose>
 * @since 2024/7/17
 */
@Component
public class OrderStatusConverter implements Converter<String> {

    @Override
    public Class<?> supportJavaTypeKey() {
        return String.class;
    }

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

    /**
     * 这里读的时候会调用
     *
     * @param context
     * @return
     */
    @Override
    public String convertToJavaData(ReadConverterContext<?> context) throws Exception {
        return Converter.super.convertToJavaData(context);
    }

    /**
     * 这里是写的时候会调用 不用管
     *
     * @return
     */
    @Override
    public WriteCellData<String> convertToExcelData(WriteConverterContext<String> context) {

        String value = context.getValue();
        if ("0".equals(value)) {
            value = "待付款";
        } else if ("1".equals(value)) {
            value = "已完成";
        }

        return new WriteCellData<>(value);
    }

}
