package constants

type FileType string

const (
	FileTypeImage    FileType = "image"
	FileTypeDocument FileType = "document"
	FileTypeVideo    FileType = "video"
	FileTypeAudio    FileType = "audio"
	FileTypeArchive  FileType = "archive"
	FileTypeOther    FileType = "other"
)

func GetAllFileTypes() []FileType {
	return []FileType{
		FileTypeImage,
		FileTypeDocument,
		FileTypeVideo,
		FileTypeAudio,
		FileTypeArchive,
		FileTypeOther,
	}
}

func IsValidFileType(fileType FileType) bool {
	for _, validType := range GetAllFileTypes() {
		if fileType == validType {
			return true
		}
	}
	return false
}

// MIME type mappings
var MimeTypeToFileType = map[string]FileType{
	// Images
	"image/jpeg":    FileTypeImage,
	"image/jpg":     FileTypeImage,
	"image/png":     FileTypeImage,
	"image/gif":     FileTypeImage,
	"image/webp":    FileTypeImage,
	"image/svg+xml": FileTypeImage,

	// Documents
	"application/pdf":    FileTypeDocument,
	"application/msword": FileTypeDocument,
	"application/vnd.openxmlformats-officedocument.wordprocessingml.document": FileTypeDocument,
	"application/vnd.ms-excel": FileTypeDocument,
	"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": FileTypeDocument,
	"text/plain": FileTypeDocument,
	"text/csv":   FileTypeDocument,

	// Videos
	"video/mp4":  FileTypeVideo,
	"video/avi":  FileTypeVideo,
	"video/mov":  FileTypeVideo,
	"video/wmv":  FileTypeVideo,
	"video/flv":  FileTypeVideo,
	"video/webm": FileTypeVideo,

	// Audio
	"audio/mpeg": FileTypeAudio,
	"audio/mp3":  FileTypeAudio,
	"audio/wav":  FileTypeAudio,
	"audio/ogg":  FileTypeAudio,
	"audio/aac":  FileTypeAudio,

	// Archives
	"application/zip":              FileTypeArchive,
	"application/x-rar-compressed": FileTypeArchive,
	"application/x-7z-compressed":  FileTypeArchive,
	"application/gzip":             FileTypeArchive,
}

func GetFileTypeFromMimeType(mimeType string) FileType {
	if fileType, exists := MimeTypeToFileType[mimeType]; exists {
		return fileType
	}
	return FileTypeOther
}
