package me.qwq.doghouse.enums;

import java.util.Objects;

import org.apache.commons.lang3.StringUtils;

import com.baomidou.mybatisplus.annotation.EnumValue;

import me.qwq.doghouse.annotation.StaticAttribute;
import me.qwq.doghouse.entity.Asset;

/**
 * 文件类型枚举
 **/
@StaticAttribute
public enum FileTypeEnum implements IQueryableEnum {

    OTHER(0, "其他"),
    IMAGE(1, "图片"),
    ARCHIVE(2, "压缩文件"),
    DOCUMENT(3, "文档"),
    MEDIA(4, "媒体文件"),
    APPLICATION(5, "应用程序");

    @EnumValue
    private final int status;
    private final String note;

    FileTypeEnum(int status, String note) {
        this.status = status;
        this.note = note;
    }

    public String getNote() {
        return note;
    }

    public int getStatus() {
        return status;
    }
    
    public static FileTypeEnum getFileType(Asset asset) {
        if (Objects.isNull(asset)) {
            return OTHER;
        }
        return getFileType(asset.getExt());
    }
    
    public static FileTypeEnum getFileType(String ext) {
        if (StringUtils.isEmpty(ext)) {
            return OTHER;
        }
        ext = ext.toLowerCase();
        switch (ext) {
        case "jpg":
        case "jpeg":
        case "gif":
        case "png":
        case "apng":
        case "bmp":
        case "svg":
        case "ico":
        case "webp":
        case "psd":
        case "tif":
        case "raw":
        case "avif":
            return IMAGE;
        case "zip":
        case "rar":
        case "7z":
        case "001":
        case "iso":
        case "xz":
        case "txz":
        case "lzma":
        case "tar":
        case "cpio":
        case "bz2":
        case "bzip2":
        case "tbz2":
        case "tbz":
        case "gz":
        case "gzip":
        case "tgz":
        case "tpz":
        case "z":
        case "taz":
        case "lzh":
        case "lha":
        case "rpm":
        case "deb":
        case "arj":
        case "vhd":
        case "wim":
        case "swm":
        case "fat":
        case "ntfs":
        case "dmg":
        case "hfs":
        case "xar":
        case "squashfs":
            return ARCHIVE;
        case "doc":
        case "docx":
        case "dot":
        case "dotx":
        case "ppt":
        case "pptx":
        case "xls":
        case "xlsx":
        case "pdf":
        case "txt":
        case "rtf":
        case "md":
            return DOCUMENT;
        case "mp3":
        case "aac":
        case "ac3":
        case "amr":
        case "ogg":
        case "ogm":
        case "ogv":
        case "dts":
        case "m1a":
        case "m2a":
        case "m4a":
        case "mp2":
        case "mpa":
        case "mpc":
        case "flac":
        case "mid":
        case "wav":
        case "wma":
        case "wmv":
        case "mp4":
        case "webm":
        case "swf":
        case "rm":
        case "rmvb":
        case "mov":
        case "mpeg":
        case "mkv":
        case "m4b":
        case "m4v":
        case "m4p":
        case "f4v":
        case "flv":
        case "3gp":
            return MEDIA;
        case "exe":
        case "msi":
        case "bat":
        case "cmd":
        case "apk":
            return APPLICATION;
        default:
            return OTHER;
        }
    }
}
