from typing import Dict, List, Optional

from pydantic import BaseModel, Field


class TestItemEntry(BaseModel):
    id: str
    content: str


class TestCaseEntry(BaseModel):
    id: str
    item_id: str
    operation_steps: List[str]
    test_content: str
    expected_result_placeholder: str


class ExpectedResultEntry(BaseModel):
    id: str
    case_id: str
    result: str


class StepLogEntry(BaseModel):
    step_name: str
    input_summary: str
    output_summary: str
    success: bool
    fallback_used: bool
    duration_ms: float


class TestingPipelineRequest(BaseModel):
    requirement_text: str = Field(..., min_length=1)
    requirement_type: Optional[str] = None
    knowledge_base_ids: List[int] = []
    retrieval_top_k: int = Field(default=8, ge=1, le=20)
    knowledge_context: Optional[str] = None
    use_model_generation: bool = True
    max_items_per_group: int = Field(default=12, ge=4, le=30)
    cases_per_item: int = Field(default=2, ge=1, le=5)
    max_focus_points: int = Field(default=6, ge=3, le=12)
    max_llm_calls: int = Field(default=10, ge=0, le=100)
    debug: bool = False


class TestingPipelineResponse(BaseModel):
    trace_id: str
    requirement_type: str
    reason: str
    candidates: List[str]
    test_items: Dict[str, List[TestItemEntry]]
    test_cases: Dict[str, List[TestCaseEntry]]
    expected_results: Dict[str, List[ExpectedResultEntry]]
    formatted_output: str
    pipeline_summary: str
    knowledge_used: bool = False
    step_logs: List[StepLogEntry] = []
