# -*- coding: utf-8 -*-
# filename: file_preview_constants.py
# @Time    : 2025-01-20
# @Author  : Claude Code
# @Email   : noreply@anthropic.com
# @Software: PyCharm
"""Constants and prompt template mapping for file preview tool"""
# 文件类型到 Prompt 模板的映射
# 用于内部自动选择合适的 prompt 模板
FILE_TYPE_PROMPT_MAPPING = {
    # 图片文件
    "image": "describe",
    # PDF 文件（转换为图片后分析）
    "pdf": "describe_pdf",  # PDF 专用模板
    # PPT 文件（每页独立截图）
    "ppt": "describe_ppt",  # PPT 专用模板
    # 其他格式不调用 LLM
    "document": None,  # Word/MD/TXT
    "excel": None,  # Excel
}


def get_prompt_template_for_file_type(file_type: str) -> str | None:
    """根据文件类型获取对应的 prompt 模板

    Args:
        file_type: 文件类型标识

    Returns:
        对应的 prompt 模板名称，如果不调用 LLM 则返回 None
    """
    return FILE_TYPE_PROMPT_MAPPING.get(file_type)


# 文件扩展名到文件类型的映射
EXTENSION_TO_FILE_TYPE = {
    # 图片格式
    ".png": "image",
    ".jpg": "image",
    ".jpeg": "image",
    ".webp": "image",
    ".gif": "image",
    ".bmp": "image",
    ".tiff": "image",
    ".tif": "image",
    ".heic": "image",
    ".heif": "image",
    # PDF
    ".pdf": "pdf",
    # 文档格式
    ".docx": "document",
    ".doc": "document",
    ".txt": "document",
    ".md": "document",
    ".markdown": "document",
    # 表格格式
    ".xlsx": "excel",
    ".xls": "excel",
    ".csv": "excel",
    # 演示格式
    ".pptx": "ppt",
    ".ppt": "ppt",
}


# MIME 类型映射
MIME_TYPE_MAPPING = {
    # 图片 MIME 类型
    "image/png": "image",
    "image/jpeg": "image",
    "image/webp": "image",
    "image/gif": "image",
    "image/bmp": "image",
    "image/tiff": "image",
    "image/heic": "image",
    "image/heif": "image",
    # PDF
    "application/pdf": "pdf",
    # 文档 MIME 类型
    "application/vnd.openxmlformats-officedocument.wordprocessingml.document": "document",
    "application/msword": "document",
    "text/plain": "document",
    "text/markdown": "document",
    # 表格 MIME 类型
    "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "excel",
    "application/vnd.ms-excel": "excel",
    "text/csv": "excel",
    # 演示 MIME 类型
    "application/vnd.openxmlformats-officedocument.presentationml.presentation": "ppt",
    "application/vnd.ms-powerpoint": "ppt",
}


def get_file_type_from_extension(extension: str) -> str | None:
    """根据文件扩展名获取文件类型

    Args:
        extension: 文件扩展名（如 '.pdf', '.jpg'）

    Returns:
        文件类型标识，如果无法识别则返回 None
    """
    return EXTENSION_TO_FILE_TYPE.get(extension.lower())


def get_file_type_from_mime_type(mime_type: str) -> str | None:
    """根据 MIME 类型获取文件类型

    Args:
        mime_type: MIME 类型字符串

    Returns:
        文件类型标识，如果无法识别则返回 None
    """
    return MIME_TYPE_MAPPING.get(mime_type.lower())
