"""
数据模型定义 - 国自然项目信息结构
"""

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


class Participant(BaseModel):
    """项目参与人"""
    name: str = Field(description="姓名")
    title: Optional[str] = Field(default=None, description="职称")
    institution: Optional[str] = Field(default=None, description="单位")


class Publication(BaseModel):
    """成果产出"""
    title: str = Field(description="成果标题")
    pub_type: Optional[str] = Field(default=None, description="类型：期刊论文/会议论文/专著/专利等")
    authors: Optional[str] = Field(default=None, description="作者")
    journal: Optional[str] = Field(default=None, description="期刊/会议名称")
    year: Optional[str] = Field(default=None, description="发表年份")


class ProjectInfo(BaseModel):
    """单个项目信息 - 包含列表页和详情页的完整字段"""
    # 基本信息（列表页可获取）
    project_name: str = Field(description="项目名称")
    project_leader: str = Field(description="项目负责人")
    institution: str = Field(description="依托单位")
    approval_no: Optional[str] = Field(default=None, description="项目批准号")
    apply_code: Optional[str] = Field(default=None, description="申请代码")
    project_type: Optional[str] = Field(default=None, description="项目类别")
    funding_amount: Optional[str] = Field(default=None, description="资助金额（万元）")
    approval_year: Optional[str] = Field(default=None, description="批准年度")
    end_year: Optional[str] = Field(default=None, description="结题年度")
    keywords: Optional[str] = Field(default=None, description="关键词")
    
    # 详情页字段
    research_period: Optional[str] = Field(default=None, description="研究期限")
    abstract_cn: Optional[str] = Field(default=None, description="中文摘要")
    abstract_en: Optional[str] = Field(default=None, description="英文摘要")
    conclusion_abstract: Optional[str] = Field(default=None, description="结题摘要")
    
    # 参与人和成果
    participants: Optional[List[Participant]] = Field(default=None, description="项目参与人")
    publications: Optional[List[Publication]] = Field(default=None, description="成果产出")
    
    # 成果统计
    paper_count: Optional[int] = Field(default=None, description="期刊论文数量")
    conference_paper_count: Optional[int] = Field(default=None, description="会议论文数量")
    patent_count: Optional[int] = Field(default=None, description="专利数量")
    book_count: Optional[int] = Field(default=None, description="专著数量")
    award_count: Optional[int] = Field(default=None, description="科研奖励数量")
    
    # 详情页链接
    detail_url: Optional[str] = Field(default=None, description="详情页URL")


class SearchResults(BaseModel):
    """搜索结果集合"""
    keyword: str = Field(description="搜索关键词")
    total_count: Optional[int] = Field(default=None, description="总结果数")
    projects: List[ProjectInfo] = Field(default_factory=list, description="项目列表")
