package com.yonge.cooleshow.biz.dal.convert;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.yonge.cooleshow.biz.dal.enums.AudioTypeEnum;

/**
 * Description
 *
 * @author liujunchi
 * @date 2022-05-20
 */
public class AudioTypeConverter implements Converter<AudioTypeEnum> {
    @Override
    public Class supportJavaTypeKey() {
        return AudioTypeEnum.class;
    }

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

    @Override
    public AudioTypeEnum convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        try {
            if ("MP3".equals(cellData.getStringValue())) {
                return AudioTypeEnum.MP3;
            } else if ("MIDI".equals(cellData.getStringValue())){
                return AudioTypeEnum.MIDI;
            } else if ("是".equals(cellData.getStringValue())) {
                return AudioTypeEnum.MP3_METRONOME;
            } else if ("否".equals(cellData.getStringValue())) {
                return AudioTypeEnum.MP3;
            } else {
                return null;
            }
        } catch (Exception e) {
            return null;
        }
    }

    @Override
    public CellData convertToExcelData(AudioTypeEnum audioTypeEnum, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        if (null != audioTypeEnum) {
            return new CellData(audioTypeEnum.getCode());
        }
        return new CellData("异常数据");
    }
}
