"""示例：直接使用 Python 生成论文."""

import sys
import os

# 添加 src 到路径
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'src'))

from mcp_docx_thesis_server.markdown_parser import parse_markdown_thesis
from mcp_docx_thesis_server.docx_generator import generate_thesis_docx
from mcp_docx_thesis_server.formats import get_format


def main():
    """生成示例论文."""
    # 读取示例 Markdown 文件
    example_path = os.path.join(os.path.dirname(__file__), 'example_thesis.md')
    with open(example_path, 'r', encoding='utf-8') as f:
        markdown_content = f.read()

    # 解析 Markdown
    content = parse_markdown_thesis(markdown_content)

    # 添加元数据
    content.metadata.author = "张明"
    content.metadata.student_id = "20211000001"
    content.metadata.college = "教育信息技术学院"
    content.metadata.major = "教育技术学"
    content.metadata.advisor = "李教授"
    content.metadata.date = "2025年3月"

    # 生成中山大学格式论文
    print("正在生成中山大学格式论文...")
    sysu_format = get_format('sysu')
    output_path_sysu = os.path.join(os.path.dirname(__file__), 'output_sysu.docx')
    generate_thesis_docx(content, sysu_format, output_path_sysu)
    print(f"✅ 中山大学格式论文已生成: {output_path_sysu}")

    # 生成华南师范大学格式论文
    print("正在生成华南师范大学格式论文...")
    scnu_format = get_format('scnu')
    output_path_scnu = os.path.join(os.path.dirname(__file__), 'output_scnu.docx')
    generate_thesis_docx(content, scnu_format, output_path_scnu)
    print(f"✅ 华南师范大学格式论文已生成: {output_path_scnu}")

    # 生成通用格式论文
    print("正在生成通用格式论文...")
    generic_format = get_format('generic')
    output_path_generic = os.path.join(os.path.dirname(__file__), 'output_generic.docx')
    generate_thesis_docx(content, generic_format, output_path_generic)
    print(f"✅ 通用格式论文已生成: {output_path_generic}")

    print("\n🎉 所有论文生成完成！")


if __name__ == '__main__':
    main()
