package com.njcn.gather.tools.report.model.enums;

/**
 * 模板文档类型枚举
 * 
 * @author hongawen
 */
public enum TemplateType {
    
    /**
     * Word文档 (.docx)
     */
    DOCX("docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"),
    
    /**
     * PDF文档 (.pdf) - 未来扩展
     */
    PDF("pdf", "application/pdf"),
    
    /**
     * Excel文档 (.xlsx) - 未来扩展
     */
    XLSX("xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
    
    private final String extension;
    private final String mimeType;
    
    TemplateType(String extension, String mimeType) {
        this.extension = extension;
        this.mimeType = mimeType;
    }
    
    public String getExtension() {
        return extension;
    }
    
    public String getMimeType() {
        return mimeType;
    }
    
    /**
     * 根据文件扩展名获取模板类型
     */
    public static TemplateType fromExtension(String fileName) {
        if (fileName == null) return DOCX;
        
        String extension = getFileExtension(fileName);
        for (TemplateType type : values()) {
            if (type.extension.equalsIgnoreCase(extension)) {
                return type;
            }
        }
        return DOCX; // 默认返回DOCX
    }
    
    /**
     * 从文件名提取扩展名
     */
    private static String getFileExtension(String fileName) {
        int lastDot = fileName.lastIndexOf('.');
        return lastDot > 0 ? fileName.substring(lastDot + 1) : "";
    }
}