package com.koobietech.eas.common.constant;


public enum ArchiveFileType {
    //OFFICE 文件
    DOC(".doc", 11, "application/msword"),
    XLS(".xls", 12, "application/vnd.ms-excel"),
    PPT(".ppt", 13, "application/vnd.ms-powerpoint"),
    XLSX(".xlsx", 14, "application/vnd.openxmlformats-office, document.spreadsheetml.sheet"),
    DOCX(".docx", 15, "application/vnd.openxmlformats-office, document.wordprocessingml.document"),
    PDF(".pdf", 16, "application/pdf"),
    //文本文件
    TXT(".txt", 21, "text/plain"),
    HTML(".html", 22, "text/html"),
    CSS(".css", 23, "text/css"),
    JS(".js", 24, "application/x-javascript"),
    //媒体文件
    JPG(".jpg", 31, "image/jpeg"),
    JPEG(".jpeg", 36, "image/jpeg"),
    GIF(".gif", 32, "image/gif"),
    MP4(".mp4", 33, "video/mp4"),
    MP3(".mp3", 34, "audio/mp3"),
    PNG(".png", 35, "image/png"),
    //压缩文件
    GZ(".gz", 41, "application/x-gzip"),
    ZIP(".zip", 42, "application/zip"),
    RAR(".rar", 43, "application/x-rar-compressed"),
    //其他文件
    FILE(".file", 51, "application/octet-stream");

    private final String suffix;
    private final int value;
    private final String contentType;

    ArchiveFileType(String suffix, int value, String contentType) {
        this.suffix = suffix;
        this.value = value;
        this.contentType = contentType;
    }

    public static String getSuffix(int fileTypeCode) {
        for (FileType fileType : FileType.values()) {
            if (fileType.getValue() == fileTypeCode) {
                return fileType.getSuffix();
            }
        }
        return null;
    }

    public String getSuffix() {
        return suffix;
    }

    public static String getContentType(String suffix) {
        //根据后缀名获取文件类型
        for (ArchiveFileType fileType : ArchiveFileType.values()) {
            if (fileType.getSuffix().equalsIgnoreCase(suffix)) {
                return fileType.getContentType();
            }
        }
        return null;
    }

    public String getContentType() {
        return contentType;
    }


    public int getValue() {
        return value;
    }
}

