"""管道数据类：请求描述、执行结果、写入结果。"""

from __future__ import annotations

from dataclasses import dataclass, field
from typing import Any


@dataclass
class PipelineRequest:
    """管道请求描述。"""

    endpoint: str
    params: dict
    page_size: int | None = 200
    data_path: tuple[str, ...] = ("data",)
    list_key: str | None = None
    segment_index: int = 0  # 所属窗口分段索引
    is_detail: bool = False  # 是否为详情请求
    detail_id: Any = None  # 详情请求的 ID
    # 预取的 API 响应（用于 BaseOdsTask 集成：iter_paginated 已获取数据，
    # _request_loop 跳过 api.post() 直接使用）
    _prefetched_response: Any = None


@dataclass
class PipelineResult:
    """管道执行结果。"""

    status: str = "SUCCESS"
    total_requests: int = 0
    completed_requests: int = 0
    total_fetched: int = 0
    total_inserted: int = 0
    total_updated: int = 0
    total_skipped: int = 0
    total_deleted: int = 0
    request_failures: int = 0
    processing_failures: int = 0
    write_failures: int = 0
    cancelled: bool = False
    errors: list[dict] = field(default_factory=list)
    timing: dict[str, float] = field(default_factory=dict)
    # Detail_Mode 统计
    detail_success: int = 0
    detail_failure: int = 0
    detail_skipped: int = 0


@dataclass
class WriteResult:
    """单次批量写入结果。"""

    inserted: int = 0
    updated: int = 0
    skipped: int = 0
    errors: int = 0
