package com.yushu.common.utils.file;

import java.util.Arrays;
import java.util.List;

/**
 * 文件预览工具类
 * 
 * @author yushu
 */
public class FilePreviewUtils
{
    /** 图片类型 */
    private static final List<String> IMAGE_TYPES = Arrays.asList(
        "jpg", "jpeg", "png", "gif", "bmp", "webp", "svg", "ico"
    );
    
    /** PDF类型 */
    private static final List<String> PDF_TYPES = Arrays.asList("pdf");
    
    /** Office文档类型 */
    private static final List<String> OFFICE_TYPES = Arrays.asList(
        "doc", "docx", "xls", "xlsx", "ppt", "pptx"
    );
    
    /** 文本类型 */
    private static final List<String> TEXT_TYPES = Arrays.asList(
        "txt", "md", "json", "xml", "html", "css", "js", "java", "py", "sql"
    );
    
    /** 视频类型 */
    private static final List<String> VIDEO_TYPES = Arrays.asList(
        "mp4", "avi", "mov", "wmv", "flv", "mkv", "webm"
    );
    
    /** 音频类型 */
    private static final List<String> AUDIO_TYPES = Arrays.asList(
        "mp3", "wav", "ogg", "aac", "flac", "m4a"
    );
    
    /**
     * 判断是否为图片
     */
    public static boolean isImage(String fileType)
    {
        return IMAGE_TYPES.contains(fileType.toLowerCase());
    }
    
    /**
     * 判断是否为PDF
     */
    public static boolean isPdf(String fileType)
    {
        return PDF_TYPES.contains(fileType.toLowerCase());
    }
    
    /**
     * 判断是否为Office文档
     */
    public static boolean isOffice(String fileType)
    {
        return OFFICE_TYPES.contains(fileType.toLowerCase());
    }
    
    /**
     * 判断是否为文本文件
     */
    public static boolean isText(String fileType)
    {
        return TEXT_TYPES.contains(fileType.toLowerCase());
    }
    
    /**
     * 判断是否为视频
     */
    public static boolean isVideo(String fileType)
    {
        return VIDEO_TYPES.contains(fileType.toLowerCase());
    }
    
    /**
     * 判断是否为音频
     */
    public static boolean isAudio(String fileType)
    {
        return AUDIO_TYPES.contains(fileType.toLowerCase());
    }
    
    /**
     * 判断是否支持在线预览
     */
    public static boolean canPreview(String fileType)
    {
        return isImage(fileType) || isPdf(fileType) || isText(fileType) 
            || isVideo(fileType) || isAudio(fileType);
    }
    
    /**
     * 获取预览类型
     */
    public static String getPreviewType(String fileType)
    {
        if (isImage(fileType)) return "image";
        if (isPdf(fileType)) return "pdf";
        if (isOffice(fileType)) return "office";
        if (isText(fileType)) return "text";
        if (isVideo(fileType)) return "video";
        if (isAudio(fileType)) return "audio";
        return "unknown";
    }
}
