package e

import "strings"

type FileType int

// 定义文件类型值
const (
	Video FileType = 1
	Audio FileType = 2
	Image FileType = 3
	File  FileType = 4
	Other FileType = 5
)

// 根据扩展名映射到文件类型值
var extensionToType = map[string]FileType{
	// 视频文件
	".3g2": Video, ".3gp": Video, ".asf": Video, ".avi": Video, ".divx": Video, ".drc": Video,
	".flv": Video, ".h261": Video, ".h264": Video, ".mkv": Video, ".mov": Video, ".mp4": Video, ".mpg": Video,
	".mpeg": Video, ".mpv": Video, ".mxf": Video, ".nuv": Video, ".qt": Video, ".rm": Video,
	".rmvb": Video, ".srt": Video, ".swf": Video, ".vob": Video, ".vp6": Video, ".vp8": Video, ".webm": Video,
	".wmv": Video, ".xesc": Video,

	// 音频文件
	".aac": Audio, ".aax": Audio, ".ac3": Audio, ".act": Audio, ".au": Audio, ".flac": Audio,
	".m4a": Audio, ".m4p": Audio, ".m4r": Audio, ".mid": Audio, ".midi": Audio, ".mp2": Audio,
	".mp3": Audio, ".mpa": Audio, ".mpc": Audio, ".ogg": Audio, ".wav": Audio, ".wma": Audio, ".wv": Audio,

	// 图像文件
	".bmp": Image, ".gif": Image, ".ico": Image, ".jpeg": Image, ".jpg": Image, ".jpe": Image,
	".png": Image, ".psd": Image, ".tiff": Image, ".webp": Image,

	// 普通文件
	".a": File, ".abw": File, ".azw": File, ".bin": File, ".bz2": File, ".c": File, ".cab": File,
	".class": File, ".conf": File, ".crt": File, ".css": File, ".csv": File, ".dat": File, ".deb": File,
	".dll": File, ".dms": File, ".doc": File, ".docx": File, ".eot": File, ".eps": File, ".exe": File,
	".gz": File, ".h": File, ".htm": File, ".html": File, ".iso": File, ".jar": File,
	".js": File, ".json": File, ".log": File, ".m3u": File, ".m3u8": File, ".md": File, ".msi": File,
	".otf": File, ".pcap": File, ".pdf": File, ".ppt": File, ".pptx": File, ".rar": File, ".rpm": File,
	".rss": File, ".run": File, ".sh": File, ".sql": File, ".svg": File, ".tar": File, ".tgz": File,
	".ttf": File, ".txt": File, ".vsd": File, ".weba": File,
	".wps": File, ".xml": File, ".xpi": File, ".zip": File, ".z": File,

	// 未知文件扩展名
	"": Other,
}

// DetectFileTypeByExtension 通过文件扩展名判断文件类型并返回对应的值
func DetectFileTypeByExtension(extension string) FileType {
	extension = strings.ToLower(extension)
	if fileType, exists := extensionToType[extension]; exists {
		return fileType
	}
	return Other
}
