#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
数据模型定义
"""

from typing import List, Optional, Tuple
from dataclasses import dataclass, field


@dataclass
class CategoryStandard:
    """标准分类定义"""
    first_code: str
    first_name: str
    first_seq: int  # 一级序号
    second_code: str
    second_name: str
    second_seq: int  # 二级序号
    second_focus: str  # 二级分类关注点
    third_code: str
    third_name: str
    third_seq: int  # 三级序号
    third_focus: str
    keywords: str = ""


@dataclass
class SecondCategoryStandard:
    """二级分类标准定义（来自construction_plan_standards.csv）"""
    first_name: str  # 一级分类中文名
    second_name: str  # 二级分类中文名
    second_raw_content: str  # 二级分类详细描述


@dataclass
class ClassifiedContent:
    """分类结果"""
    third_category_name: str  # 三级分类名称
    third_category_code: str  # 三级分类代码
    third_seq: int  # 三级序号
    start_line: int
    end_line: int
    content: str  # 原文内容


@dataclass
class SectionContent:
    """二级标题内容"""
    section_key: str  # 如 "第一章->一"
    section_name: str  # 如 "一）编制依据"
    lines: List[str]  # 原始行列表
    numbered_content: str  # 带行号的内容
    category_standards: List[CategoryStandard] = field(default_factory=list)  # 该二级分类下的三级标准
    line_number_map: List[int] = field(default_factory=list)  # 每行对应的全局行号（如果有）
    chunk_ranges: List[Tuple[str, int, int]] = field(default_factory=list)  # [(chunk_id, global_start, global_end), ...]


@dataclass
class ClassificationResult:
    """分类结果"""
    model: str
    section_key: str
    section_name: str
    classified_contents: List[ClassifiedContent]
    latency: float
    raw_response: str = ""
    error: Optional[str] = None
    total_lines: int = 0  # 该section的总行数
    classified_lines: int = 0  # 已分类的行数
    coverage_rate: float = 0.0  # 分类率（已分类行数/总行数）
