package com.uas.eis.utils;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.springframework.http.HttpStatus;
import org.springframework.web.multipart.MultipartFile;

import java.io.*;
import java.util.Map;
import java.util.UUID;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;

public class FileUtil {


    public static String getContentType(String fileName) {
        if (null == fileName || "".equals(fileName)) {
            return "application/octec-stream";
        }
        String ext = FilenameUtils.getExtension(fileName).toLowerCase();
        String contentType = null;
        switch (ext) {
            case "pdf":
                contentType = "application/pdf";
                break;
            case "xls":
                contentType = "application/vnd.ms-excel";
                break;
            case "xlsx":
                contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                break;
            case "doc":
            case "dot":
                contentType = "application/msword";
                break;
            case "docx":
                contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
                break;
            case "dotx":
                contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.template";
                break;
            case "ppt":
            case "pot":
            case "pps":
            case "ppa":
                contentType = "application/vnd.ms-powerpoint";
                break;
            case "pptx":
                contentType = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
                break;
            case "potx":
                contentType = "application/vnd.openxmlformats-officedocument.presentationml.template";
                break;
            case "ppsx":
                contentType = "application/vnd.openxmlformats-officedocument.presentationml.slideshow";
                break;
            case "jpg":
            case "png":
            case "gif":
                contentType = "image/*";
                break;
            case "avi":
            case "mpg":
            case "mpeg":
            case "mp4":
                contentType = "video/*";
                break;
            case "mp3":
            case "wav":
                contentType = "audio/*";
                break;
            default:
                contentType = "application/octec-stream";
                break;
        }
        return contentType;
    }
}
