package com.dtok.framework.util;

import org.springframework.stereotype.Component;

import java.io.File;

@Component
public class FileUtils {

    public static final String TYPE_JPG = ".jpg";

    public static final String TYPE_GIF = ".gif";

    public static final String TYPE_PNG = ".png";

    public static final String TYPE_BMP = ".bmp";

    public static final String TYPE_MP3 = ".mp3";

    public static final String TYPE_WAV = ".wav";

    public static final String TYPE_M4A = ".m4a";

    public static final String TYPE_MP4 = ".mp4";

    public static final String TYPE_UNKNOWN = "unknown";


    public static boolean delFile(File file) {
        if (file.exists()) {
            String name = file.getName();
            file.delete();
            System.out.println("文件 [" + name + "] 已经删除！");
            return true;
        }
        return false;
    }

    /**
     * 获取文件类型
     * type:1-图片，2-音频，3-视频
     *
     * @return {@link String}
     */
    public static String getFileType(String suffixName) {
        String type = null;
        switch (suffixName) {
            case TYPE_JPG:
            case TYPE_GIF:
            case TYPE_PNG:
            case TYPE_BMP:
                type = "1";
                break;
            case TYPE_MP3:
            case TYPE_WAV:
            case TYPE_M4A:
                type = "2";
                break;
            case TYPE_MP4:
                type = "3";
                break;
            default:
                break;
        }
        return type;
    }

}
