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

import cn.iocoder.yudao.module.member.enums.SpaceCapsuleOrderEnum;
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 OrderSpaceCapsuleStatusConverter implements Converter<Integer> {

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

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

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

    /**
     * 这里是写的时候会调用 不用管
     *
     * @return
     */
    @Override
    public WriteCellData<String> convertToExcelData(WriteConverterContext<Integer> context) {
        Integer value = context.getValue();
        String s1=null;
        if (SpaceCapsuleOrderEnum.SPACE_CAPSULE_ORDER_ENUM_UNUSED.getCode().equals(value)) {
            s1 = SpaceCapsuleOrderEnum.SPACE_CAPSULE_ORDER_ENUM_UNUSED.getName();
        } else  if (SpaceCapsuleOrderEnum.SPACE_CAPSULE_ORDER_ENUM_DONE.getCode().equals(value)) {
            s1 = SpaceCapsuleOrderEnum.SPACE_CAPSULE_ORDER_ENUM_DONE.getName();
        }else  if (SpaceCapsuleOrderEnum.SPACE_CAPSULE_ORDER_ENUM_IN_USE.getCode().equals(value)) {
            s1 = SpaceCapsuleOrderEnum.SPACE_CAPSULE_ORDER_ENUM_IN_USE.getName();
        }
        else  if (SpaceCapsuleOrderEnum.SPACE_CAPSULE_ORDER_ENUM_REFUNDED.getCode().equals(value)) {
            s1 = SpaceCapsuleOrderEnum.SPACE_CAPSULE_ORDER_ENUM_REFUNDED.getName();
        }
        else  if (SpaceCapsuleOrderEnum.SPACE_CAPSULE_ORDER_ENUM_APPOINTMENT.getCode().equals(value)) {
            s1 = SpaceCapsuleOrderEnum.SPACE_CAPSULE_ORDER_ENUM_APPOINTMENT.getName();
        }
        return new WriteCellData<>(s1);
    }

}
