#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
模块名称：functional_report.py
模块描述：功能测试报告 Pydantic 数据模型

作者：czj
创建日期：2026-08-12
最后修改：2026-08-12
"""

from typing import Dict, List, Optional
from pydantic import BaseModel, Field


class UploadResponse(BaseModel):
    """上传Excel文件响应"""
    session_id: str = Field(..., description="会话ID")
    testcase_path: str = Field(..., description="测试用例文件路径")
    buglist_path: str = Field(..., description="BUG列表文件路径")
    message: str = Field("文件上传成功", description="提示信息")


class GenerateRequest(BaseModel):
    """生成报告请求"""
    session_id: str = Field(..., description="会话ID")
    project_name: str = Field("", description="项目名称")
    report_format: str = Field("docx", description="报告格式: docx/md/both")
    template_id: Optional[int] = Field(None, description="报告模板ID（None 时使用默认模板或系统默认配置）")

    # ERP上传选项（可选，勾选后在生成报告后自动上传）
    upload_to_erp: bool = Field(False, description="是否上传到ERP测试单")
    upload_to_project: bool = Field(False, description="是否上传到项目资料")
    upload_to_cooperation: bool = Field(False, description="是否上传到协作文档")

    # ERP测试单配置
    developtesting_id: Optional[int] = Field(None, description="测试单ID")
    copyuser_names: List[str] = Field(default_factory=list, description="抄送人姓名列表")
    createuser_name: Optional[str] = Field(None, description="创建人姓名")

    # 项目资料配置
    project_id: Optional[int] = Field(None, description="项目资料的项目ID")
    project_file_name: Optional[str] = Field(None, description="项目资料的文件名称")

    # 协作文档配置
    cooperation_project_id: Optional[int] = Field(None, description="协作文档的项目ID")
    cooperation_file_name: Optional[str] = Field(None, description="协作文档的文件名称")
    cooperation_group_id: Optional[int] = Field(None, description="协作文档的分组ID")


class GenerateResponse(BaseModel):
    """生成报告响应"""
    session_id: str = Field(..., description="会话ID")
    project_name: str = Field(..., description="项目名称")
    case_analysis: Dict = Field(..., description="用例分析结果")
    bug_analysis: Dict = Field(..., description="BUG分析结果")
    case_bug_link_count: int = Field(0, description="用例-BUG关联数")
    charts: Dict[str, str] = Field(default_factory=dict, description="图表文件路径")
    reports: List[str] = Field(default_factory=list, description="报告文件路径列表")
    erp_results: List[Dict] = Field(default_factory=list, description="ERP上传结果列表")


class DownloadResponse(BaseModel):
    """下载报告响应"""
    report_path: str = Field(..., description="报告文件路径")
    filename: str = Field(..., description="文件名")


class UploadToErpRequest(BaseModel):
    """上传到ERP请求"""
    session_id: str = Field(..., description="会话ID")
    report_filename: str = Field(..., description="报告文件名（从generate接口返回的reports列表中选择）")
    developtesting_id: Optional[int] = Field(None, description="测试单ID，默认使用系统配置")
    copyuser_names: List[str] = Field(default_factory=list, description="抄送人姓名列表")
    createuser_name: Optional[str] = Field(None, description="创建人姓名")


class UploadToErpResponse(BaseModel):
    """上传到ERP响应"""
    success: bool = Field(..., description="是否成功")
    report_id: Optional[int] = Field(None, description="ERP报告ID")
    message: str = Field(..., description="提示信息")


class UploadToProjectRequest(BaseModel):
    """上传文件到ERP项目资料请求"""
    session_id: str = Field(..., description="会话ID")
    report_filename: str = Field(..., description="要上传的报告文件名")
    project_id: int = Field(..., description="关联的项目ID")
    name: Optional[str] = Field(None, description="文件名称（默认取文件名）")


class UploadToCooperationRequest(BaseModel):
    """上传文件到ERP协作文档请求"""
    session_id: str = Field(..., description="会话ID")
    report_filename: str = Field(..., description="要上传的报告文件名")
    project_id: int = Field(..., description="关联的项目ID")
    name: Optional[str] = Field(None, description="文件名称（默认取文件名）")
    group_id: Optional[int] = Field(None, description="分组ID（可选）")


class UploadFileToErpResponse(BaseModel):
    """上传文件到ERP（项目资料/协作文档）响应"""
    success: bool = Field(..., description="是否成功")
    file_id: Optional[int] = Field(None, description="ERP文件ID")
    message: str = Field(..., description="提示信息")


class ErpConfigResponse(BaseModel):
    """ERP配置响应"""
    api_key: str = Field("", description="API密钥")
    base_url: str = Field("", description="基础URL")
    developtesting_id: int = Field(0, description="默认测试单ID")
    type_id: int = Field(2, description="报告类型ID")
    image_url_prefix: str = Field("", description="图片URL前缀")


class ErpConfigUpdateRequest(BaseModel):
    """ERP配置更新请求"""
    api_key: Optional[str] = Field(None, description="API密钥")
    base_url: Optional[str] = Field(None, description="基础URL")
    developtesting_id: Optional[int] = Field(None, description="默认测试单ID")
    type_id: Optional[int] = Field(None, description="报告类型ID")
    image_url_prefix: Optional[str] = Field(None, description="图片URL前缀")


class ReportInfoResponse(BaseModel):
    """报告信息响应"""
    session_id: str = Field(..., description="会话ID")
    reports: List[Dict] = Field(default_factory=list, description="报告文件列表")
    charts: List[Dict] = Field(default_factory=list, description="图表文件列表")
    analysis: Dict = Field(default_factory=dict, description="分析结果缓存")